Professional Documents
Culture Documents
Measured data
Set value
(Such as upper or lower limit)
- Measured
value is
-9.9999.
- Error Response
Measured data
Set value
(Such as upper or lower limit)
In order to exchange data between control device and measurement instrument, there are many measurement instruments that
support serial communication.
Other than KEYENCE products, there are many devices such as scales, power meters, inverters, temperature controllers, etc. that
can be used for serial communication.
2
2. Mechanism of Serial Communication
What Send/Receive Mode is Used?
Command/Response Mode
When a command is sent, the receiving device returns a response.
- Measured
value is
-9.9999.
- Error Response
- It is ABCD.
Data
Not only serial communication devices, but also PLC has data exchange system (operation mode). The following
page will describe a PLC data exchange system (operation mode).
3
2. Mechanism of Serial Communication
What Operation Mode is Used?
For Higher-Level Link: used for communications with various measurement instruments
[Explanation] A mode in which commands that can be used in PLC are sent from PC in advance and PLC automatically
sends back the responses. Programs are created by a PC, PLC’s ladder diagram program is not required.
Command
Response
For Communication With External Device: used for reading data from PCs, etc.
[Explanation] A mode in which PLC creates and sends protocol/command corresponding to serial
communication the devices, or creates program to receive commands sent from serial devices.
Command
Response
4
2. Mechanism of Serial Communication
What Commands/Responses are Sent and Received?
Examples of Commands/Responses
With the Commands/Responses mode that sends/receives commands and responses, usually the command receiving
side will specify device-specific commands, therefore, the sending device needs to create and send commands that
are suitable for the receiving device.
In the case of KEYENCE displacement sensor – GT2 Series, when “M0” command is received, the measured values
are sent back as responses from all sensor amplifiers.
Example: read measured values from GT2 Series. (Please refer to a manual of each device for details of commands)
Command
PLC M 0 CR LF GT2 Series
(Displacement sensor)
Send measured value.
Measured value is
-9.9999.
Response
M 0 – 9 . 9 9 9 9 CR LF
Command M 0 CR LF
Send measured value.
Now, in the following page, data composition typical to serial communication devices is introduced.
Using the ASCII Code Chart (the table on the right), let’s convert “M” to a
Lower
numerical data. 4 bits
From “M” in the ASCII Code Chart, take vertical and horizontal directions
to find numbers assigned for the line and column.
5
2. Mechanism of Serial Communication
What is the Composition of Command/Response?
Composition of Command/Response
Commands for serial communication are communication device-specific. It is necessary for PLC to send data based
on the protocol* of the receiving communication device. Details of protocol are described in a manual of serial
communication device.
* Protocol: Rules for device-to-device communication.
Please note that depending on the device, some settings may not be necessary for these items.
Read all data from all sensor amplifi ers (MO command)
Command
M O CR LF
Response
Data of the sensor amplifier with Data of the sensor amplifier with Data of the sensor amplifier with
M O ....... CR LF
ID:00 ID:01 the last ID No.
, , , ,
For the protocol of GT2 Series, there are No Header, Station Number, Data Length or Check Code, therefore,
it is necessary to establish communication based on this protocol.
In order to establish serial communication, not only sending commands normally but communication settings such
as the baud rate of the two devices must match. In “3. Points for Communication Settings”, necessary parameters to
be set for serial communication are introduced.
6
2. Mechanism of Serial Communication
[FOR YOUR REFERENCE]
Check code is an error detection data to check occurrences of data corruption due to noise, etc. in communication.
Computation Computation
Add
A B
A B Data normal
A B Data error
There are several types of check code according to the difficulty level of the computation method or reliability.
Typical computation methods are as follows:
· Checksum *Please refer to a creation example below
Hexadecimal
ASCII Code number
"A" 41
+ "B" 42
+ "C" 43
+ "D" 44
+ "E" 45
A higher byte 1 is truncated since a check code of 1 byte is used in this example.
7
2. Mechanism of Serial Communication
[FOR YOUR REFERENCE]
Check of Command/Response
Check Method for Command/Response
There may be occasions that the communication with serial communication devices can not be properly established
even when sending a command after confirming a protocol. In such cases, it is necessary to check what types
of data are exchanged between devices. A general check method is to connect a protocol analyser* between
communication devices. However, using a serial communication unit (KV-L20V) enables data exchange check
without a protocol analyser.
* Protocol analyser … a device to analyse communication data
When using the serial communication unit (KV-L20V), Commands and Responses can be checked by computers.
Screen for check when using the serial communication unit (KV-L20V)
Command Normal
ending
Communication
Command Delimiter
Response
8
3. Points for Communication Settings
What Settings are Necessary When Connecting to Serial Communication
Devices?
There are RS-232C and RS-422/485 interfaces that support serial devices.
Please check interface!
Difference between RS-232C and RS-422/485
RS-232C PLC
Communication
(1:1 communication only)
distance:
up to 15 m
When baud rates are different, some data cannot be received and normal data transmission is not possible.
*Also in the case of higher baud rate of receiving side, you cannot establish communication.
9
3. Points for Communication Settings
What Settings are Necessary to Connect with Serial Communication Devices?
Data bit length specifi es the number of bytes a datum is composed of.
Please select data bit length from either “7 bit” or “8 bit”!
1 2 3 4
When the above six communication settings are matched between the two devices, communication
is ready. Since preparation for serial communication is completed, please create commands and start
sending them to serial communication devices.
www.keyence.com
Copyright
Copyyrig (c) (c)
ight 20102010
(c KEYENCE CORPORATION.
KEYENCE CORPORAll rights
PORA reserved.
ATION
TIO . All rights rese
erve
ved
d. KVSerial-WW-EN1102-E 1091-2 E 600
6008887 Printed in Japan
apan KVSerial-WW-EN1102-E 1091-2 E 600887
* 6 0 0 8 8 7 *