Application Example - Omron CJ - REFERENCE MANUAL 07-2009 Reference Manual

Communications commands
Hide thumbs Also See for CJ - REFERENCE MANUAL 07-2009:
Table of Contents

Advertisement

Application Example

2-3
Application Example
Sending a Host Link Command from a Host Computer
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$
140 INPUT #1,R$
150 PRINT "RECV DATA=";R$
160 IF MID$(R$,4,2)="EX"THEN GOTO 210
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...
400 *FCSCHCK
410 L=LEN(RESPONSE$)
420 Q=0:FCSCK$=""
430 A$=RIGHT$(RESPONSE$,1)
440 PRINT RESPONSE$,A$,L
450 IF A$="*"THEN LENGS=LEN(RESPONSE$)
ELSE LENGS=LEN(RESPONSE$)
460 FCSP$=MID$(RESPONSE$,LENGS+1,2)
470 FOR I=1 TO LENGS
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$
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
14
In this example program, a Host Link command is sent from a host computer
and a response is received.
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.
2
Number of characters in FCS calculation
Sends command to PLC.
Receives command from PLC.
Identifies command.
Transmission/reception data
3
FCS data that is received
FCS calculation result
Section 2-3

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents