RS-232C interface

(3) Microsoft QuickBASIC sample program

CLS

STX$ = CHR$(&H2): ETX$ = CHR$ (&H3): NAK$ = CHR$(15): ACK$ = CHR$(&H6) PRINT "*** RS-232C COMMUNICATION SAMPLE PROGRAM ***"

PRINT "Type Command 'QUIT' to quit."

PRINT

REM *** Communication Port Initial & Open ***

REM Port 1,9600Bps,No parity,8 bit data,1 stop bit

OPEN "COM1:9600,N,8,1" FOR RANDOM AS #1 LEN = 256

REM *** Input Command & Send Command ***

SendCmd:

INPUT "Input Command ="; SEND$

IF SEND$ = "QUIT" THEN GOTO ProgEnd

PRINT #1, STX$ + SEND$ + ETX$

REM *** Wait for Receive Command ***

WHILE LOC(1) = 0 WAITKEY$ = INKEY$

IF WAITKEY$ = "Q" THEN PRINT "*** Quit ***": GOTO ProgEnd

WEND

REM *** Receive Command ***

RecvCmd:

RECV$ = INPUT$(1, #1)

IF RECV$ = STX$ THEN RECV$ = "[Stx]"

IF RECV$ = ACK$ THEN RECV$ = "[Ack]"

IF RECV$ = NAK$ THEN RECV$ = "[Nak]"

IF RECV$ = ETX$ THEN BUFFER$ = BUFFER$ + "[Etx]": GOTO DispOut BUFFER$ = BUFFER$ + RECV$

GOTO RecvCmd

REM *** Output Receive Command ***

DispOut:

PRINT "Receive Command ="; BUFFER$

PRINT

BUFFER$ = ""

GOTO SendCmd

REM *** End Program ***

ProgEnd:

CLOSE

END

MICROSOFT QUICKBASIC is a registered trade mark of Microsoft Corporation.

– 98 –

Page 98
Image 98
Panasonic AJ-D850P manual Microsoft QuickBASIC sample program, Cls