当前位置:网站首页>Modbus Protocol

Modbus Protocol

2020-12-06 23:30:09 havealex

Modbus agreement

summary

Modbus Is the world's first real bus protocol for industrial field .Modbus The network is an industrial communication system , It is composed of programmable controller with intelligent terminal and computer connected by public line or local special line . The system structure includes hardware 、 Software is also included . It can be applied to various data acquisition and process monitoring . Now? Modbus It supports serial link and Ethernet link , According to the agreement, there is Modbus RTU、Modbus ASCII、Modbus TCP. Now the most used is based on the serial link Modbus RTU And Ethernet based Modbus TCP Two kinds of . It is stipulated in the national standard that , On the serial link ,Modbus RTU Agreement is the default , and Modbus ASCII For optional .

Modbus Agreement that

The order of packet bytes is in the order of high order , Low in the back ( Big end model ) Unit 1Byte Equipment code ,1byte Function code ,N data , RTU 2byteCRC( The small end ) The Internet 6Byte baotou

The Internet 6Byte baotou 2byte Packet count ( The small end ),2byte agreement ( Set up 0),2byte Segment length

Unit 1byte Equipment code ,1-255 Range 1byte Function code , | Function code | describe | |:--------:| -------------:| | 1 | Read 01,DO | | 2 | Read 02,DI | | 3 | Read 03,AO | | 4 | Read 04,AI | | 5 | Write single 01,DO | | 6 | Write single 03,AO | | 15 | Write multiple 01,DO | | 16 | Write multiple 03,AO |

N Data can be classified as read , Write once , Write many times 1. Send request packet when reading unit structure :

Equipment code Function code Initial address register (2byte) Number M
1byte 1byte 2byte 2byte

Normal reply | Equipment code | Function code | The number of bytes in the data segment N | Data segment bytes | | -------- | ----- | ----- | ----- | | 1byte | 1byte | 1byte | N individual byte |

1,2 Data table exists (M+7)/8 = N 3,4 Data table exists M*2=N

Abnormal reply | Equipment code | Function code F | Error code E | | -------- | ----- | ----- | | 1byte | 1byte(F|0x80) | 1byte |

E Error code situation 01 The requested data table does not exist 02 Read overflow ( Initial address + The length cannot be found )

  1. Write alone
Equipment code Function code Initial address The setting value of the target register
1byte 1byte 2byte 2byte

Reply frame

Equipment code Function code Initial address The setting value of the target register
1byte 1byte 2byte 2byte

Abnormal reply ( Same as above )

3. Write more than one

Equipment code Function code Initial address Number of registers n data byte length data byte
1byte 1byte 2byte 2byte 1byte Nbyte
among , When the number of registers is n when , Corresponding to the data length byte The length is :
When it comes to 1,2 Table time , The number of bytes occupied is : (n+7)/8
When it comes to 3,4 Table time , The number of bytes occupied is : n*2

Normal reply | Equipment code | Function code | Initial address | Number of registers n | | -------- | ----- | ----- | ----- | | 1byte | 1byte | 2byte | 2byte |

Abnormal reply ( Same as above )

The Internet Modbus TCP 6byte baotou +ModbusUnit | Packet count ( The small end )| agreement | Unit The number of bytes of the part | Modbus-unit part | | -------- | ----- | ----- | ----- | | 2byte | 2byte agreement ( Set up 0) | Nbyte | Nbyte

Data conversion float 3.14 mem 0xF5C3 0x4048 mem C3 F5 48 40

Big end data + Big end transmission transfer 40 48 F5 C3 convert 1 C3 F5 48 40

Small end data transmission C3 F5 48 40

Big end swap transmission 48 40 C3 F5 uint8[] convert 1 0x4048 0xF5C3 uint16[] 0xF5C3 0x4048 C3 F5 48 40 UINT8[]

The small end swap transmission F5 C3 40 48 convert1 48 40 c3 f5 0x4048 0xf5c3 0xf5c3 0x4048

libmodbus Chinese manual details

https://blog.csdn.net/qq_23670601/article/details/82155378

Libmodbus Manual Page

https://libmodbus.org/docs/v3.1.4/

Industrial control system safety ——Modbus Learning notes

https://cloud.tencent.com/developer/article/1045841 Modbus The agreement involves DI、DO、AI、DO Four tables

There are four types of control data :

  • DI:DigitalInput( Digital input , Discrete input ), One address, one data bit , The user can only read its state , Do not modify . With a bit Express On/Off, State input used to record control signals , for example : switch , contact point , The motor runs , Transfinite switch… wait . On PLC It's called Input relay、input coil etc. .

  • DO:DigitalOutput( Digital output , Coil output ), One address, one data bit , The user can set the location 、 Reset , You can read back the status . With a bit Express On/Off, Used to output control signals , To activate or stop the motor , Alarm bell , The light … wait . On PLC It's called Output relay、Output coil etc. .

  • AI:Analog Input( Analog input , Input register ), An address 16 Bit data , Users can only read , Do not modify ,, With 16 bits integer Represents a number , A numerical input used to record control signals , for example : temperature 、 Traffic 、 Amount of material 、 Speed 、 speed 、 File board opening 、 level 、 weight … wait . On PLC It's called Input register.

  • AO:AnalogOutput( Analog output , Holding register ), An address 16 Bit data , Users can write , It can also be read back , With 16 bits integer Represents a number , Used to control the output of a signal , for example : temperature 、 Traffic 、 Speed 、 speed 、 File board opening 、 The amount of feed … Wait for the set value . On PLC It's called Output register、Holding register.

Modbus-TCP and Modbus-RTU The difference between :http://www.szyuanhao.com/news/573.html

Modbus rtu and Modbus tcp The essence of both agreements is MODBUS agreement , All depend on MODBUS Register address to exchange data ; But the hardware used is different ,Modbus RTU Generally, serial port is used RS232C or RS485/422, and Modbus TCP Ethernet port is generally used . There are many protocol converters on the market now , These different protocols can be easily converted to each other Such as :Intesisbox You can put modbus rtu convert to Modbus tcp actually Modbus The agreement includes ASCII、RTU、TCP. The standard Modicon Controller use RS232C Realize serial Modbus.Modbus Of ASCII、RTU The message protocol 、 Structure of data 、 Command and answer , Data communication uses Maser/Slave The way .Modbus Of TCP The message protocol 、 Structure of data 、 The way to command and respond , Data communication uses Server/Client The way .

Modbus The protocol needs to verify the data , In addition to parity check in serial protocol ,ASCII Mode adoption LRC check ,RTU Mode adoption 16 position CRC check . ModbusTCP The mode has no additional requirements for validation , because TCP The protocol is a reliable connection oriented protocol .

TCP and RTU The agreement is very similar , Just put RTU The two byte check code of the protocol is removed , And then in RTU The beginning of the agreement plus 5 individual 0 And a 6 And pass TCP/IP The network protocol can be sent out .

Modbus Related references

版权声明
本文为[havealex]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201206232229997j.html