C sample programs, Appendix c sample programs, Sample programs for multi-drop link – KEYENCE N-400 User Manual
Page 132

Appendices
124
Appendices
Appendix C
Sample Programs
Sample programs for multi-drop link
The following program (QBASIC) is an example of a serial communication program
for multi-drop link mode and multi-head mode.
The bar code data read by the BL series, along with the transmitted command and
response to the command can be displayed.
Enter the commands using the keyboard and press the [Return] key to send the
command.
Set the N-400 as follows:
• Header: None
• Delimiter: [CR]
• Handshaking protocol: No handshaking or PASS/RTRY protocol
100
'***N-400 SAMPLE PROGRAM********************************
110
'CLS 3
120
DAT$ = "": RD$ = "": CM$ = ""
130
OPEN "COM1:9600,E,7,1,RS,CS,DS,CD" FOR RANDOM AS #1
140
'*BUFFCLR '***CLEARING BUFFER***************************
150
A = LOC(1)
160
IF A <> 0 THEN R$ = INPUT$(1, #1): GOTO 140
165
'
170
'*MAIN '***MAIN ROUTINE*********************************
180
A = LOC(1)
190
K$ = INKEY$
195
WHILE K$ <> "E"
200
IF K$ <> "" THEN GOSUB 410
210
IF A = 0 THEN 170
220
RD$ = INPUT$(1, #1)
320
IF RD$ = CHR$(&HD) THEN GOSUB 1000: GOTO 170
330
DAT$ = DAT$ + RD$
340
GOTO 170
400
'
410
'*COMMAND :'***TRANSMITTING COMMAND*********************
420
IF K$ = CHR$(&HD) THEN 470
440
CM$ = CM$ + K$
450
PRINT K$;
460
RETURN
470
'*SEND
480
PRINT #1, CM$; CHR$(&HD); : 'TRANSMITTING COMMAND
490
PRINT : PRINT CM$; " WAS SENT"
500
CM$ = ""
510
RETURN
520
'
1000 '*RECEIVE :'***RECEIVING*******************************
1010 LDAT$ = LEFT$(DAT$, 2)
1020 IF LDAT$ = "%P" THEN GOSUB 2000: RETURN
1030 IF LDAT$ = "%T" THEN GOSUB 3000: RETURN
1040 GOSUB 3000: RETURN
1050 '
2000 '*DATA RECEIVE :'***RECEIVING DATA*********************
2010 MDAT$ = MID$(DAT$, 6, 4)
2020 IF MDAT$ = "OVER" THEN GOSUB 4000: RETURN
2030 MDAT$ = MID$(DAT$, 6, 2)
2040 IF MDAT$ = "NC" THEN GOSUB 5000: RETURN
2050 MDAT$ = MID$(DAT$, 6, 4)
2060 IF MDAT$ = "SERR" THEN GOSUB 6000: RETURN
2070 MDAT$ = MID$(DAT$, 6, 1)
2080 IF MDAT$ = "e" THEN GOSUB 7000: RETURN
2090 GOSUB 8000: RETURN