KEYENCE BL-700 Series User Manual

Page 145

Advertising
background image

131

Appendices

Appendices

Appendix E Example Program for Serial Communication

The following is a example program that allows data communication and command
communication. Type in a command and press [Enter] to send the data to the BL-
700.
Only the QUIT command can be sent by pressing [Q].
Set the BL-700 as follows:

Header: [STX]

Delimiter: [ETX]

Handshaking protocol: No handshaking or PASS/RTRY handshaking

Baud rate: 9600 bps, 7 bit, 1 stop bit, Even parity

100 ’***BL-700 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 ’***Clear Buffer********************************************
150 A=LOC(1)
160 IF A<>0 THEN R$=INPUT$(1,#1) :GOTO 140
200 ‘
210 ’***Main Routine***********************************************
220 K$=INKEY$
230 IF K$<>”” THEN GOSUB 410
240 A=LOC(1)
250 IF A<>0 THEN GOSUB 320
260 GOTO 210
310 ‘
320 ’***Receive Data*************************************************
330 IF RD$=CHR$(&H02) THEN RD$=””
340 IF RD$=CHR$($H03) THEN GOSUB 710 :RETURN :GOTO 210
350 IF RD$=CHR$($H0D) THEN GOSUB 610 :RETURN :GOTO 210
360 DAT$=DAT$+RD$
370 RETURN
400 ‘
410 ’***Send Command********************************************
420 IF K$=CHR$(&H0D) THEN 470
430 IF K$=”Q” AND CM$=”” THEN CM$=”QUIT”:GOTO 470
440 PRINT K$;
450 CM$=CM$+K$
460 RETURN
470 ’
480 PRINT #1, CM$;CHR$(&H0D);
490 PRINT:PRINT CM$;”command is sent”
500 CM$=””
510 RETURN
600 ‘
610 ’***Display response data to the command*******************
620 PRINT DAT$ ;”is sent back”
630 DAT$=””
640 RETURN
700 ‘
710 ’***Display Bar Code Data***********************************
720 PRINT DAT$ ;”is read”
730 DAT$$=””
740 RETURN

Note: This sample program is shown for your reference only. Please note that this
may not work correctly depending on the version of BASIC you use.

Advertising