Technology Sharing

Communication Protocol_Modbus Protocol Introduction

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Concept Introduction

  • Modbus protocol: A serial communication protocol that was published by Modicon (now Schneider Electric) in 1979 for communication using programmable logic controllers (PLCs). Modbus has become the de facto industry standard for communication protocols and is now a common connection method between industrial electronic devices.
  • Communication figurative explanation: Similar to the human communication process, it requiresCommunication Role(master-slave, client-server...),Communication medium(Serial, Ethernet, Wireless...),letter of agreement(modbus, S7, MC...) three elements.
  • Three elements of network protocol:grammar(structure or format of data and control information),Semantics(what kind of control information is sent), synchronization (detailed description of the order of event implementation, matching speed, etc.).

Introduction to modbusRTU protocol

Grammatical structures:

  • Address code: used to identify slave devices, ranging from 0 to 247, where 0 is the broadcast address and all slave devices will receive data at this address.
  • Function code: used to indicate the type of operation to be performed, such as reading a register value, writing a single register, etc.
  • Data: includes register address, data value and other information. The content and length of the data will vary depending on the function code.
  • CRC checksum: used to detect whether there is an error in the data transmission process. Add two bytes of CRC checksum at the end of the data frame. After receiving the data, the receiver recalculates the CRC checksum and compares it with the received CRC checksum. If they are different, it means that there is an error in the data transmission process.

function code:

  • Function code 01: Read Coils, used to continuously read the status of 1 to 2000 coils from a remote device.
  • Function code 02: Read Inputs, obtain the current ON/OFF status of a set of switch inputs.
  • Function code 03: Read Holding Registers, obtain the current binary value in one or more holding registers.
  • Function code 04: Read Input Registers, obtain the current binary value in one or more input registers.
  • Function code 05: Force Single Coil, forces the on/off state of a logic coil.
  • Function code 06: Preset Single Register, load a specific binary value into a holding register.
  • Function code 15: Force Multiple Coils, which forces a series of continuous logic coils to be on or off.
  • Function code 16: Preset Multiple Registers, loads specific binary values ​​into a series of continuous holding registers.

example:
Read (03) the curtain opening degree in slave station (01) (read from the second one: 00 02 read one bit 00 01 CRC check 25 CA):
insert image description here
insert image description here