Omron C200HE User Manual

Page of 564
425
8-2-3 Example Programs
Command Transmission
The following type of program must be prepared in the host computer to receive
the data. This program allows the computer to read and display the data re-
ceived from the PC while a host link read command is being executed to read
data from the PC.
10 ’C200HX/HG/HE SAMPLE PROGRAM FOR EXCEPTION
20 CLOSE
30 CLS
40 OPEN ”COM:E73” AS #1
50 
KEYIN
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?=”,B$
110 IF B$=”Y” THEN GOTO 130 ELSE GOTO 
KEYIN
120 S$=ST$
130 PRINT #1,S$
Sends command to PC
140 INPUT #1,R$
Receives response from PC
150 PRINT ”RECV DATA = ”;R$
160 IF MID$(R$,4,2)=”EX” THEN GOTO 210 ’
Identifies command from PC
170 IF RIGHT$(R$,1)<>”
” THEN S$=” ”:GOTO 130
180 GOTO 
KEYIN
190 CLOSE 1
200 END
210 PRINT ”EXCEPTION!! DATA”
220 GOTO 140
Example Program for FCS
This example shows a BASIC subroutine program for executing an FCS check
on a frame received by the host computer.
400 *FCSCHECK
410 L=LEN(RESPONSE$) ’
Data transmitted and received
. . . . . . . . . . 
420 Q=0:FCSCK$=” ”
430 A$=RIGHT$(RESPONSE$,1)
440 PRINT RESPONSE$,AS,L
450 IF A$=”*” THEN LENGS=LEN(RESPONSE$)-3 
              ELSE LENGS=LEN(RESPONSE$)-2
460 FCSP$=MID$(RESPONSE$,LENGS+1,2) ’
FCS data received
.
 
.
 
470 FOR I=1 TO LENGS ’
Number of characters in FCS
. . . . . . . . . . 
480 Q=ASC(MID$(RESPONSE$,I,1)) XOR Q
490 NEXT I
500 FCSD$=HEX$(Q)
510 IF LEN(FCSD$)=1 THEN FCSD$=”0”+FCSD$ ’
FCS result
520 IF FCSD$<>FCSP$ THEN FCSCK$=”ERR”
530 PRINT”FCSD$=”;FCSD$,”FCSP$=”;FCSP$,”FCSCK$=”;FCSCK$
540 RETURN
Note
1. Normal reception data includes the FCS, delimiter or terminator, and so on.
When an error occurs in transmission, however the FCS or some other data
may not be included. Be sure to program the system to cover this possibility.
2. In this program example, the CR code (CHR$(13)) is not entered for RE-
SPONSE$. When including the CR code, make the changes in lines 430
and 450.
TXD(––) Application Example This example shows a program for using the RS-232C port in the Host Link
mode to transmit 10 bytes of data (DM 0000 to DM 0004) to a computer. From
DM 0000 to DM 0004, “1234” is stored in every word.
Host Link Communications
Section 8-2