Modem INP & OUT ports

Area:    Quik_Bas
  Msg:    #344
 Date:    02-04-93 10:55 (Public) 
 From:    Rick Pedley              
 To:      Calvin French            
 Subject: Modem INP & OUT ports    
 On 02-02-93 Calvin French wrote to All... 
 
 CF> Hi! I'm new to this echo, but what I'm wondering is how I  
 CF> can access the _other_ com ports (3 & 4). OPEN "COM4 etc.."  
 
 
Here's some code posted by Dick Dennison that'll help: 
 
 
' DIAL    BAS : Dial a phone number on the screen 
' author .....: Dick Dennison [74270,3636] 1:272/34 914-374-3903 *hst 24 hrs 
' supports ...: COM1 - COM4 
' syntax .....: DIAL portnum% 
' includes ...: None 
' notes ......: Move the cursor with the arrow keys to the phone number 
'             : Press the spacebar and move the right arrow key across 
'             : the number and press Enter 
'             : Uses Basic's OPEN COMx commands 
' cost .......: Free = Credit where credit due 
'             : Do not use as is for commercial use - may not be resold 
'             : May not be rebundled without prior written consent 
' dated ......: 10/19/91,10/9/92 
' credits ....: Thanks to Mike Welch for CLIPMSG, and Pete Petrakis for his 
'             : notes on Com Port swapping. 
 
DECLARE SUB Hangup (port%) 
DECLARE SUB Getnum (row%, Col%, markit%, port%) 
DECLARE SUB Setup (port%) 
 
LOCATE 1, 1 
 
doscolor% = SCREEN(1, 1, -1) 
fg% = doscolor% AND &HF 
bg% = doscolor% / &H10 AND 6   '&H7 - 1 
 
COLOR 0, 7 
LOCATE 24, 1 
PRINT "     Move the cursor to the beginning of the phone number and_ 
     press Space       " '<<< wrapped line 
PRINT "                             DIALX from Dick Dennison"; 
GOTO Here 
LOCATE 10, 1 
IF VAL(COMMAND$) < 1 OR VAL(COMMAND$) > 4 THEN      'Get the portnum% 
     PRINT "Port number must be on command line" 
     END 
ELSE port% = VAL(COMMAND$) 
END IF 
Here: 
port% = 2          'Hard code the port here 
                    
'================================================== 
'Setup some special key functions 
CR$ = CHR$(13) 
Nul$ = CHR$(0) 
ArrowLt$ = Nul$ + CHR$(75) 
ArrowRt$ = Nul$ + CHR$(77) 
ArrowUp$ = Nul$ + CHR$(72) 
ArrowDn$ = Nul$ + CHR$(80) 
EndKey$ = Nul$ + CHR$(79) 
Esc$ = CHR$(27) 
BackSp$ = CHR$(8) 
Home$ = Nul$ + CHR$(71) 
SpaceBar$ = CHR$(32) 
'=================================================== 
 
'Save vectors at bios Addresses for Com1-Com2 
DEF SEG = 0 
  OldPort1H = PEEK(&H400) 
  OldPort1L = PEEK(&H401) 
  OldPort2H = PEEK(&H402) 
  OldPort2L = PEEK(&H403) 
DEF SEG 
 
'================================================================== 
'Move cursor around 
DO                         'This section lets the user move 
 In$ = INKEY$             'move the cursor around on the screen 
 SELECT CASE In$          'to the beginning of the phone number 
  CASE CHR$(48) TO CHR$(57) 
     numflag% = -1 
     count% = count% + 1 
     markit% = -1 
     PRINT In$; 
  CASE CR$ 
    IF markit% THEN       'A CR signals the end of the highlight 
     row% = CSRLIN 
     Col% = POS(0) - count% 
    IF numflag% THEN count% = count% - 1 
     EXIT DO 
    END IF 
  CASE Esc$                'END 
    END 
  CASE Home$               'Goto the beginning of the line 
     LOCATE , 1 
  CASE EndKey$             'Goto the end of the line 
     LOCATE , 80 
  CASE ArrowUp$            'UpArrow 
     x% = CSRLIN 
     IF x% > 1 THEN LOCATE x% - 1 
  CASE ArrowDn$            'DownArrow 
     x% = CSRLIN 
     IF x% < 25 THEN LOCATE x% + 1 
  CASE ArrowLt$                                 'LeftArrow 
     IF POS(0) > 1 THEN LOCATE , POS(0) - 1 
     IF markit% THEN count% = count% - 1    'If markit% then ' ' was pressed 
  CASE ArrowRt$                             'RightArrow 
      
     IF markit% THEN 
          count% = count% + 1               'If markit% then ' ' was pressed 
          row% = CSRLIN: Col% = POS(0) 
          a% = SCREEN(row%, Col%) 
          PRINT CHR$(a%); 
     ELSE 
          IF POS(0) < 80 THEN LOCATE , POS(0) + 1 
     END IF 
  CASE BackSp$ 
     IF POS(0) > 1 THEN         'Backspace with delete 
         count% = count% - 1 
         LOCATE , POS(0) - 1 
         PRINT " "; 
         LOCATE , POS(0) - 1 
     END IF 
  CASE SpaceBar$ 
     IF markit% THEN 
          count% = count% + 1          'If markit% then ' ' was pressed 
          row% = CSRLIN: Col% = POS(0) 
          a% = SCREEN(row%, Col%) 
          PRINT CHR$(a%); 
     ELSE 
          BEEP 
          markit% = -1                      'Flag set for marking number 
     END IF 
 END SELECT 
 LOCATE , , 1                   'Keep cursor flashing 
LOOP 
'====================================================================== 
 
         'Get the phone number off the screen 
Getnum row%, Col%, count%, port% 
 
         'Restore old vectors 
CLOSE 1 
 
'DEF SEG = 0 
'   POKE &H400, OldPort1H 
'   POKE &H401, OldPort1L 
'   POKE &H402, OldPort2H 
'  POKE &H403, OldPort2L 
'DEF SEG 
 
COLOR fg%, bg%

END 
 
SUB Getnum (row%, Col%, markit%, port%) 
GOTO Here1: 
IF row% < 1 THEN row% = 1 
IF Col% < 1 THEN Col% = 1 
LOCATE row%, Col% 
FOR x% = 0 TO markit%           'Read the phone number off the screen 
     a% = SCREEN(row%, Col% + x%) 
     Dialstr$ = Dialstr$ + CHR$(a%) 
NEXT x% 
Here1: 
Dialstr$ = "544-1573" 
LOCATE 23, 25 
PRINT "        Dialing : "; Dialstr$; "        "; 
LOCATE 25, 1 
PRINT "         Pickup handset and then press space or ESC when phone rings"; 
                           'Insert 12 spaces after `rings'-----------------^ 
COLOR 7, 0 
 
Setup port% 
PRINT #1, "ATM1DP" + Dialstr$     'Dial the number 
LOCATE 24, 1 
DO 
     b$ = INKEY$ 
     IF b$ = " " THEN 
          Hangup port% 
          EXIT DO 
     END IF 
     IF b$ = CHR$(27) THEN 
          Hangup port% 
          EXIT DO 
     END IF 
LOOP 
 
END SUB 
 
SUB Hangup (port%) 
 
PRINT SPACE$(25) + "...Disconnecting 1"; 
SELECT CASE port%                'Drop DTR 
    CASE 1 
        OUT &H3FC, (INP(&H3FC) AND 254)   'com1 
    CASE 2 
        OUT &H2FC, (INP(&H2FC) AND 254)   'com2 
'    CASE 3 
'        OUT &H3FC, (INP(&H3FC) AND 254)   'com3 
-end-

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET