Sign In
Celebrating 50years
divider line

Serial Interface Program In Quick Basic

The serial interface program listed in Table 1 works with QuickBasic 4.0/4.5 or Qbasic on an IBM PC (or compatible) running DOS or in a DOS window with a serial interface. It uses the COM1 communication port at 9600 Baud. Use the following procedure to develop the Serial Interface Program in Quick Basic.


1.  Start the Basic program.

2.  Enter the program exactly as presented in Table 1.

3.  Adjust the Com port and Baud rate in the program as necessary.

4.  Lengthen the "TIMEOUT" count if necessary.

5.  Save the program.

6.  Run the program.

7.  Type a command query as described in your instrument User's Manual, in the chapter called Remote Interface.

8.  Type "EXIT" to quit the program.



Table 1. Quick Basic Serial Interface Program. See SERIAL_QB.TXT.



       CLS                                               'Clear screen



       TIMEOUT = 2000                                    'Read timeout (may need more)

       BAUD$ = "9600"

       TERM$ = CHR$(13) + CHR$(10)                       'Terminators are <CR><LF>

       OPEN "COM1:" + BAUD$ + ",O,7,1,RS" FOR RANDOM AS #1 LEN = 256


LOOP1: LINE INPUT "ENTER COMMAND (or EXIT):"; CMD$       'Get command from keyboard

       CMD$ = UCASE$(CMD$)                               'Change input to upper case

          IF CMD$ = "EXIT" THEN CLOSE #1: END            'Get out on Exit

       CMD$ = CMD$ + TERM$

       PRINT #1, CMD$;                                   'Send command to instrument

       IF INSTR(CMD$, "?") <> 0 THEN                     'Test for query

          RS$ = ""                                       'If query, read response

          N = 0                                          'Clr return string and count

          WHILE (N < TIMEOUT) AND (INSTR(RS$, TERM$) = 0)  'Wait for response

            IN$ = INPUT$(LOC(1), #1)                     'Get one character at a time

            IF IN$ = "" THEN N = N + 1 ELSE N = 0        'Add 1 to timeout if no chr

            RS$ = RS$ + IN$                              'Add next chr to string

          WEND                                           'Get chrs until terminators

          IF RS$ <> "" THEN                              'See if return string is empty

            RS$ = MID$(RS$, 1, (INSTR(RS$, TERM$) - 1))  'Strip off terminators

            PRINT "RESPONSE:"; RS$                       'Print response to query


            PRINT "NO RESPONSE"                          'No response to query

          END IF

       END IF                                            'Get next command

       GOTO LOOP1