This Modbus protocol library implements the most commonly used data functions as well as some control functions. More...
This Modbus protocol library implements the most commonly used data functions as well as some control functions.
The functions to perform PLC program download and other device specific functions are outside the scope of this library.
All Bit Access and 16 Bits Access Modbus Function Codes have been implemented. In addition the most frequently used Diagnostics Function Codes have been implemented. This rich function set enables a user to solve nearly every Modbus data transfer problem.
The following table lists the supported Modbus function codes:
Function Code | Current Terminology | Classic Terminology |
---|---|---|
Bit Access | ||
1 | Read Coils | Read Coil Status |
2 | Read Discrete Inputs | Read Input Status |
5 | Write Single Coil | Force Single Coil |
15 (0F hex) | Write Multiple Coils | Force Multiple Coils |
16 Bits Access | ||
3 | Read Multiple Registers | Read Holding Registers |
4 | Read Input Registers | Read Input Registers |
6 | Write Single Register | Preset Single Register |
16 (10 Hex) | Write Multiple Registers | Preset Multiple Registers |
22 (16 hex) | Mask Write Register | Mask Write 4X Register |
23 (17 hex) | Read/Write Multiple Registers | Read/Write 4X Registers |
Diagnostics | ||
7 | Read Exception Status | Read Exception Status |
Vendor Specific | ||
100 (64 hex) | Read Log History | |
Advantech | Send/Receive ADAM 5000/6000 ASCII commands |
|
All master data and control functions are designed thread-safe. All methods of a particular MbusMaster... object can only be accessed by one thread at the same time. In addition, access to the register array objects is synchronized to allow concurrent access. This enables one thread to update a register array while a second thread is sending the data to a Modbus slave. In this case the update thread must also synchronize his access to the register array by embedding the access into a synchronized(regArr) clause.
Using multiple instances of a MbusMaster... class enables concurrent protocol transfer on different communication channels (e.g. multiple TCP/IP sessions in separate threads or multiple COM ports in separate threads).