14
Application Example Section 2-3
2-3 Application Example
Sending a Host Link Command from a Host Computer
In this example program, a Host Link command is sent from a host computer
and a response is received.
10 ’CS1 SAMPLE PROGRAM FOR EXCEPTION
20 CLOSE
30 CLS
40 OPEN “COM:E73”AS#1
50 *KEYIIN
60 INPUT ”DATA
–”,S
70 IF S$=””THEN GOTO 190
80 PRINT ”SEND DATA=”;S$
90 ST$=S$
100 INPUT ”SEND OK? Y or N?=”,BS
110 IF B$=”Y” THEN GOTO 130 ELSE GOTO *KEYIN
120 S$=ST$
130 PRINT #T,S$ Sends command to PLC.
140 INPUT #1,R$ Receives command from PLC.
150 PRINT ”RECV DATA=”;R$
160 IF MID$(R$,4,2)=”EX”THEN GOTO 210 Identifies command.
170 IF RIGHT$(R$,1)<>”*”THEN S$=””:GOTO 130
180 GOTO *KEYIN
190 CLOSE 1
200 END
210 PRINT ”EXCEPTION!!DATA”
220 GOTO 140
Explanation
1,2,3... 1. The host computer’s transmission/reception program is started up, and the
Host Link command is input.
2. The Host Link command that was input is sent to the PLC, and the data
that is received is displayed on the screen.
Note The example program up to this point does not include an error processing
routine in case reception is not normal (e.g., if there is no FCS). Include error
processing routines when creating an actual program.
400 *FCSCHCK
410 L=LEN(RESPONSE$) Transmission/reception data
420 Q=0:FCSCK$=””
430 A$=RIGHT$(RESPONSE$,1)
440 PRINT RESPONSE$,A$,L
450 IF A$=”*”THEN LENGS=LEN(RESPONSE$)
–3
ELSE LENGS=LEN(RESPONSE$)
–2
460 FCSP$=MID$(RESPONSE$,LENGS+1,2) FCS data that is received
470 FOR I=1 TO LENGS Number of characters in FCS calculation
480 Q=ASC(MID$(RESPONSE$1,1))XOR Q
490 NEXT 1
500 FCSD$=HEX$(Q)
510 IF LEN(FCSD$) =1 THEN FCSD$=”0”+FCSD$ FCS calculation result
520 IF FCSD$<>FCSP$ THEN FCSCK$=”ERR”
530 PRINT ”FCSD$=”;FCSD$,”FCSP$=”;FCSP$,”FCSCK$=”;FCSCK$
Normal FCS reception: “ ” (space); abnormal FCS reception: “ERR”
540 RETURN