3) Microsoft QuickBASIC sample program
CLS
STX$ = CHR$(&H2): ETX$ = CHR$(&H3): NAK$ = CHR$(15): ACK$ = CHR$(&HG)
PRINT "*** RS-232C COMMUNICATION SAMPLE PROGRAM ***"
PRINT "Type Command ’QUIT’ to quit."
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 #l LEN = 256
REM *** Input Command & Send Command ***
SendCmd:
INPUT "Input Command ="; SEND$
IF SENDS =
"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$
BUFFER$ = ""
GOTO SendCmd
REM *** End Program ***
ProgEnd:
CLOSE
END
–E-13–
MICROSOFT QUICKBASIC is a registered trade mark of Microsoft Corporation.