Modbus - Paiet/Capstone GitHub Wiki
Modbus Protocol
Modbus is a communication protocol commonly used in industrial control systems. It uses a client-server model and can be transmitted over serial communication lines such as RS-232 or RS-485, or over Ethernet TCP/IP.
Frame Format
Modbus messages are made up of function codes and data payloads, enclosed in a frame structure. The frame structure consists of:
- Address field: 8-bit value that identifies the slave device being addressed.
- Function code: 8-bit value that specifies the type of operation to be performed.
- Data field: variable-length field that contains the payload data.
- CRC: 16-bit field that is used for error detection.
Function Codes
Modbus supports a wide range of function codes, which specify the type of operation to be performed. Some of the most commonly used function codes include:
- Read Coils (0x01): reads the status of digital output coils.
- Read Discrete Inputs (0x02): reads the status of digital input contacts.
- Read Holding Registers (0x03): reads the current value of analog output registers.
- Read Input Registers (0x04): reads the current value of analog input registers.
- Write Single Coil (0x05): sets the value of a single digital output coil.
- Write Single Register (0x06): sets the value of a single analog output register.
- Write Multiple Coils (0x0F): sets the values of multiple digital output coils.
- Write Multiple Registers (0x10): sets the values of multiple analog output registers.
Error Handling
Modbus uses a simple error detection mechanism based on CRC. If an error is detected, the slave device will respond with an exception code, indicating the type of error that occurred.
Security Considerations
Modbus protocol does not provide any inherent security mechanisms, leaving devices using this protocol open to potential attacks. As such, it is important to implement additional security measures, such as firewalls, VPNs, and intrusion detection systems, to protect against unauthorized access and data tampering.