Download SYSMAC CS/CJ/CP Series SYSMAC One NSJ Series

Transcript
Section 2-3
Application Example
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
410
420
430
440
450
460
470
480
490
500
510
520
530
540
14
*FCSCHCK
L=LEN(RESPONSE$)
Transmission/reception data
Q=0:FCSCK$=îî
A$=RIGHT$(RESPONSE$,1)
PRINT RESPONSE$,A$,L
IF A$=î*îTHEN LENGS=LEN(RESPONSE$)–3
ELSE LENGS=LEN(RESPONSE$)–2
FCSP$=MID$(RESPONSE$,LENGS+1,2)
FCS data that is received
FOR I=1 TO LENGS
Number of characters in FCS calculation
Q=ASC(MID$(RESPONSE$1,1))XOR Q
NEXT 1
FCSD$=HEX$(Q)
IF LEN(FCSD$) =1 THEN FCSD$=î0î+FCSD$
FCS calculation result
IF FCSD$<>FCSP$ THEN FCSCK$=îERRî
PRINT îFCSD$=î;FCSD$,îFCSP$=î;FCSP$,îFCSCK$=î;FCSCK$
Normal FCS reception: “ ” (space); abnormal FCS reception: “ERR”
RETURN