Your SICK ID gives you access to our extensive range of services. This includes direct online orders, price and availability checks, and access to our digital services.
Modbus RTU - based on RS485 How to read/ write registers
Article No: KA-09073
Version: 1.4
Subject to change without notice
1) Topology and termination
2) Modbus RTU protocol
3) Function Code
4) Examples
Related Products
OLS20-BB1118142 OPTICAL LINE GUIDANCE
OLS20-UB1118340 OPTICAL LINE GUIDANCE
MLSE-0200C2NUA MAGN.LANE SENSOR
OLS20-BB1118342 OPTICAL LINE GUIDANCE
CSS-WBFA54118RZZZZZZZZZZZZ7ZZ1
GLS100G-1MBB1GZ
CSS-WBF114118RZZZZZZZZZZZZ7ZZ1
CSS-WBG4C4118RZZZZZZZZZZZZTZZ1
CSS-WBGAD4118RZZZZZZZZZZZZTZZ1
MLSE-0400C2NUA MAGN.LANE SENSOR
OLS20-UB1118140 OPTICAL LINE GUIDANCE
Table of Contents
Find here some information about sensors which have a Modbus RTU interface.
1) Topology and termination
1a) point-to-point connection
In that case the sensor can have an integrated termination and the sensor address doesn't matter
1b) bus operation in line topology
Each sensor must be configured with a different sensor address
only for sensors without integrated termination resistor
1c) Example for a point-to-point connection
For a reliable communication we recommend making a ground connection
2) Modbus RTU protocol
Modbus RTU Frame
field 1
field 2
field 3
field 4
Sensor Address
Function Code
Data
CRC
field 1
Sensor Address 1 - 247
field 2
determines if Read or Write parameter single or multiple register
field 3
data content of read parameter resp. content of Write parameter
field 4
CRC validation check
3) Function Code (field 2)
the function code must match to the requested register address, otherwise an exception Response will happen (see yellow part on the right side)
Function Code
Register Type
comment
Exception Response
Exception Code
3
Read Holding Registers
r/w Register
130 (0x82)
01 = Illegal Function 02 = Illegal Data Address 03 = Illegal Data Value
4
Read Input Registers
ro Register
131 (0x83)
6
Write Single Holding Register
write one parameter - only 1 Register
134 (0x86)
16
Write Multiple Holding Registers
write a parameter >1 Register
or write a block of parameter
144 (0x90)
4) Examples
4a) find here one example how to read process data with our Color Sensor CSS
for reading process data we must use the function code 4, which is for read only input registers.
In our example the measurement value has 6 Byte, to read all needed values we need 3 register: start from register address 199 until 201
each register has 16 Bit
the address directory can be found in the operating instruction of the particular sensor.
199 - 201 = Read 6 Byte measurement value
Field 1
Field 2
Field 3
Field 4
Sensor Address
Function Code
Start Address
Number of Register Register = 16Bit
CRC
Request
10
4 Read ro Register
199
3
client -> server
0x0A
0x04
0x00C7
0x0003
0x008D
Response
repeat Address
repeat Code
Number of Byte
Data
CRC
server -> client
0x0A
0x04
0x06
0x0325FED9FC8C
0xFEE1
Result in decimal
L = luminance
8,05
a = +red / -green
-2,95
b = +yellow / -blue
-8,84
4b) how to read and change a configuration parameter
for reading parameter we must use code 3, which is for read/write register
for changing the parameter we have 2 options:
code 6, which is for writing one single register
code 16, which is for writing multiple registers (or for writing a block of serial parameters)
here You see one simple example for the color sensor CSS, how to read the status of sender configuration with code 3 and then how to change the configuration with code 6