The text of a manual · part 52 of 68
Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual: SECTION 8 Serial Communications, pages 468 to 476
Pages 468 to 476 of 613, from Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual
The original document is the PDF (3.8 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the Omron C200H-SP001 and Omron C200HW-PA204
Page 468
SECTION 8 Serial Communications This section provides an overview of the serial communications (Host Link, RS-232C, one-to-one links, NT links, and protocol macros) that operate through the RS-232C, RS-422/485, and Peripheral Ports. 8-1 8-2
8-3
8-4 8-5 8-6
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Host Link Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2-1 Host Link Command Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2-2 Host Link Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2-3 Example Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . RS-232C Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3-1 Communications Frame Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3-2 Communications Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3-3 Application Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . One-to-one PC Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NT Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Protocol Macro Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6-1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6-2 Communications Board Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6-3 Communications Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6-4 Application Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
460 461 461 464 467 468 469 469 471 472 474 475 475 478 479 482
459
Page 469
Section
Introduction
8-1
8-1
Introduction The RS-232C port and peripheral port built into the C200HX/HG/HE PC’s CPU Unit support the following communications functions: • Communications with Programming Devices (e.g., Programming Console or a computer running the SYSMAC-CPT Support Software.) • Host Link communications with personal computers and other external devices. • RS-232C (no-protocol) communications with personal computers and other external devices. • One-to-one link communications with another PC. • NT link communications (one-to-one or one-to-N) with Programmable Terminals (PTs) equipped with an NT link interface. In addition to these communications functions, optional Communications Boards that support Protocol Macros can be installed in most C200HX/HG/HE PCs. The following table summarizes the communications functions.
Function Host Link
Connected device
Connection
Summary
Host computer or PT
One-to-one or One-to-N
Provides communications between a host computer and PC.
Related instructions Host Link commands, TXD(236)
The PC’s operating status and the contents of data areas can be monitored from the host computer. TXD(236) can be used to transmit data from the PC’s data areas to the host computer. RS-232C (no protocol)
Host computer or One-to-one other RS-232C device
TXD(236) and RXD(235) can be used TXD(236), RXD(235) to manage simple data transfer sequences such as inputs from bar code readers or outputs to printers. Control signals RS, CS, ER, and DR can be controlled by the instructions.
One-to-one Link
PC
One-to-one
Makes a one-to-one connection between two PCs using the LR areas of the PCs.
NT Link
PT
Protocol Macro
Other serial device
One-to-one or One-to-N One-to-one or One-to-N
Provides data transfers between the --PC and one or more PTs. The Protocol Macro function allows PMCR(260) the user to define separate data transfer sequences and transfer messages. Up to 1,000 communications sequences can be registered. A support program is provided that simplifies creation of communications sequences.
460
---
Page 470
Section
Host Link Communications
8-2
8-2
Host Link Communications
8-2-1 Host Link Command Summary Host Link communications are used to transfer data between the PC and a host computer (a personal computer or PT). It is possible to monitor the PC’s operating status and the contents of PC data areas from the host computer using Host Link commands. It is also possible to transfer data from the PC’s IOM data areas (IR area, SR area, LR area, HR area, AR area, timer and counter PVs, DM 0000 through DM 6143, and EM 0000 through EM 6143) to a host computer using the TXD(236) instruction in the ladder program. RS-232C Connections (1-to-1) Only one PC can be connected with the host computer (one-to-one connection) when the Host Link is made with RS-232C connections.
Host Link
Host Link Host computer
Host link
IBM PC/AT or compatible
RS-422/485 Connections (1-to-N)
Up to 32 PCs can be connected with the host computer (one-to-N connection) when the Host Link is made with RS-422/485 connections. See note
Host link
IBM PC/AT or compatible See note
See note
See note
32 PCs max.
Wiring Ports
Note:
RS-232C ↔ RS-422/485 Adapter
Use the wiring diagram shown below as a guide in wiring the port to the external device. Refer to documentation provided with the computer or other external device for wire details for it.
461
Page 471
Section
Host Link Communications
8-2
The connections between the C200HX/HG/HE and a personal computer are illustrated below as an example. C200HX/HG/HE
Personal computer
Signal
Pin No.
Pin No.
Signal
FG
1
1
–
SD
2
2
RD
RD
3
3
SD
RS
4
4
DTR
CS
5
5
SG
–
6
6
DSR
–
7
7
RS
–
8
8
CS
SG
9
9
–
Shielded cable
Applicable Connectors The following connectors are applicable. One plug and one hood are included with the CPU Unit. Plug:
XM2D-0901 (female) for IBM PC/AT or compatible (OMRON) or equivalent Hood: XM2S-0911 (OMRON) or equivalent Note Ground the FG terminal on the PC and at the computer to 100 Ω or less. Refer to the PC’s Installation Manual and to the documentation for your computer for details. Host Link Parameters
The following parameters in the PC Setup must be set in advance to enable Host Link communications. Communications Mode Set the communications mode to Host Link mode. (This is the default setting.) RS-232C port: Set bits 12 through 15 of DM 6645 to 0. Peripheral port: Set bits 12 through 15 of DM 6650 to 0. Node Number Setting When 1:N connections are being used, set a unique node number from 00 to 31. When a 1:1 connection is being used, set the PC’s node number to 00. RS-232C port: Set bits 00 through 07 of DM 6648 (00 to 31). Peripheral port: Set bits 00 through 07 of DM 6653 (00 to 31). Standard Port Settings Standard settings or custom settings can be used for the RS-232C and peripheral ports. The standard settings are used when the following bits are set to 0. (The custom settings are explained below.) RS-232C port: Bits 00 through 03 of DM 6645 (0: standard; 1: custom). Peripheral port: Bits 00 through 03 of DM 6650 (0: standard; 1: custom). The standard settings are shown in the following table. Item
462
Setting
Start bits
1
Data length
7
Stop bits
2
Parity
Even
Baud rate
9,600 bps
Page 472
Section
Host Link Communications
8-2
Custom Port Settings Standard settings or custom settings can be used for the RS-232C and peripheral ports. The custom settings are used when the following bits are set to 1. RS-232C port: Bits 00 through 03 of DM 6645 (0: standard; 1: custom). Peripheral port: Bits 00 through 03 of DM 6650 (0: standard; 1: custom). The custom settings for the RS-232C port are defined in DM 6646 and the custom settings for the peripheral port are defined in DM 6651. The following settings are valid only when pin 5 on the CPU Unit’s DIP switch is turned OFF. Be sure to set the communications parameters to the same settings for both ends of the communications.
Bit 15
0
DM 6646: RS-232C port DM 6651: Peripheral port
Transmission Frame Format (See table below.) Baud rate (See table below.)
Parameter Transmission Frame Format
Parameter Baud rate
Setting
Start bits
Data length
Stop bits
Parity
00 01 02 03 04 05 06 07 08 09 10 11
1 1 1 1 1 1 1 1 1 1 1 1
7 7 7 7 7 7 8 8 8 8 8 8
1 1 1 2 2 2 1 1 1 2 2 2
Even Odd None Even Odd None Even Odd None Even Odd None
Setting 00 01 02 03 04
Baud rate 1,200 bps 2,400 bps 4,800 bps 9,600 bps 19,200 bps
Transmission Delay Time Depending on the devices connected to the RS-232C port, it may be necessary to allow time for transmission. When that is the case, set the transmission delay to regulate the amount of time allowed. The transmission delay time is set in units of 10 ms. RS-232C port: Set DM 6647 from 0000 to 9999 (0 to 99.99 s delay). Peripheral port: Set DM 6652 from 0000 to 9999 (0 to 99.99 s delay).
463
Page 473
Section
Host Link Communications
8-2
Note If pin 5 of the CPU Unit’s DIP switch is ON, the standard communications settings will be used regardless of the settings in the PC Setup. The standard settings are as follows: Item
Setting
Node number
00
Start bits
1
Data length
7
Stop bits
2
Parity
Even
Baud rate
9,600 bps
Transmission delay time
None
8-2-2 Host Link Communications Host link communications are executed by means an exchange of commands and responses between the host computer and the PC. The command or response data that is transferred in one exchange is known as a frame and one frame can contain up to 131 characters of data. The frame formats for Host Link commands transmitted from the host computer and responses returned from the PC are described below. The PC automatically returns an ASCII-code response when it receives an ASCII-code command from the host computer. The host computer must have a program that controls the transmission and reception of the commands and responses. Command Frame Format
@
When transmitting a command from the host computer, prepare the command data in the format shown below.
x 101 x 100
Node no.
Header code
Text
FCS
↵
Terminator
The header code and text depend on the Host Link command being transmitted. When a composite command is transmitted, there will be a second sub-header code. The FCS (Frame Check Sequence) code is calculated at the host computer and set in the command frame. The FCS calculation is described later in this section. The command frame may be up to 131 characters long. A command of 132 characters or more must be divided into more than one frame. To split the command, use a carriage return delimiter (↵, CHR$(13)) instead of a terminator. A terminator must be used at the end of the last frame. When dividing commands such as WR, WL, WC, or WD that execute write operations, be careful not to divide into separate frames data that is to be written into a single word. Be sure to divide frames so that they coincide with the divisions between words. Item
Function
@
An “@” symbol must be placed at the beginning of every command.
Node no.
Identify the PC by the node number set in DM 6648 of the PC Setup.
Header code Set the 2-character command code.
464
Text
Set the command parameters.
FCS
Set a 2-character Frame Check Sequence code.
Terminator
Set two characters, and the carriage return (CHR$(13)) to indicate the end of the command.
Page 474
Section
Host Link Communications Response Frame Format
@
The response from the PC is returned in the format shown below. Prepare a program so that the response data can be interpreted and processed.
x 101 x 100
Node no.
8-2 x 161 x 160
Header code
End code
Text
FCS
↵
Terminator
The header code and text depend on the Host Link command that was received. The end code indicates the completion status of the command (e.g., whether or not an error has occurred). When the response is longer than 131 characters, it will be divided into more than one frame. A carriage return delimiter (↵, CHR$(13)) instead of a terminator will automatically be set at the end of the frame. A terminator will be set at the end of the last frame. Item
Function
@
An “@” symbol is placed at the beginning of every response.
Node no.
The PC’s node number set in DM 6648 of the PC Setup.
Header code
The 2-character command code is returned.
Text
The results of the command are returned.
FCS
The 2-character Frame Check Sequence code is returned.
Terminator
Two characters, and the carriage return (CHR$(13)) indicate the end of the response.
FCS (Frame Check Sequence) When a frame is transmitted, an FCS code is placed just before the delimiter or terminator in order to check whether an error has occurred in the transmission. The FCS is 8-bit data converted into two ASCII characters. The 8-bit data is the result of an EXCLUSIVE OR performed on the data from the beginning of the frame until the end of the text in that frame (i.e., just before the FCS). Calculating the FCS each time a frame is received and checking the result against the FCS that is included in the frame makes it possible to check for data errors in the frame.
@
1
0
Node no.
R
R
0
0
Header code
0 Text
1
4
2 FCS
↵
Terminator
FCS calculation range ASCII code @
40
1
31
0
30
R
52
1 Calculation result
31
0100 0000 EOR 0011 0001 EOR 0011 0000 EOR 0101 0010 0011 0100 i 4
0001 0010 i Converted to hexadecimal. 2 Handled as ASCII characters.
465
Page 475
Section
Host Link Communications Communications Sequence
8-2
The right to send a frame is called the “transmission right.” The Unit that has the transmission right is the one that can send a frame at any given time. The transmission right is traded back and forth between the host computer and the PC each time a frame is transmitted. An example communications sequence between the host computer and PC is described below. • The host computer sets a delimiter at the end of the first command frame and transmits the frame. • When the PC receives the delimiter, it returns the same delimiter to the host computer. • After receiving the delimiter from the PC, the host computer transmits the next frame. • The PC sets a delimiter at the end of the first response frame and transmits the frame. • When the host computer receives the delimiter, it returns the same delimiter to the PC. • After receiving the delimiter from the host computer, the PC transmits the next frame. • Long transmissions are managed by exchanging delimiters in this way. The last frame ends with a terminator. Frame2 (command)
Frame3 (command)
Text
Text
Text
FCS Delimiter
FCS Delimiter
FCS Terminator
Frame1 (command) @ Unit No. Header code Host computer
PC
Delimiter
Delimiter
@ Unit No. Header code End code Text FCS Terminator Frame (response)
Using the TXD(236) Instruction The TXD(236) instruction can be used to transmit data from the PC’s data area to the host computer. There is no response from the host computer. The TXD(236) instruction will be executed after the response has been transmitted if TXD(236) is executed while a response to a Host Link command is being returned to the host computer. Host computer No response @ Unit No. Header code PC
Text FCS Terminator
466
Page 476
Section
Host Link Communications
8-2
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 received 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 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 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 THEN S$=” ”:GOTO 130 180 GOTO 190 CLOSE 1 200 END 210 PRINT ”EXCEPTION!! DATA” 220 GOTO 140
Example Program for FCS
Note
TXD(236) Application Example
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 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 RESPONSE$. When including the CR code, make the changes in lines 430 and 450. 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.
467