A master-slave relationship is used to construct the request-response protocol known as Modbus. Communication in a master-slave relationship always takes place in pairs; one device must make a request and the other must wait for a response. The initiating device (master) is in charge of starting every interaction. Normally, the slave is a sensor, programmable logic controller (PLC), or programmable automation controller (PAC), and the master is a human-machine interface (HMI) or Supervisory Control and Data Acquisition (SCADA) system. The various protocol levels determine the content of these inquiries and answers as well as the network layers through which these communications are transmitted.
HOW DOES MODBUS COMMUNICATION PROTOCOL WORK?
Any application that uses the RTU scenario must have a Modbus master device and at least one slave device since the Remote Terminal Unit (RTU) of this kind of open standard uses a master and slave strategy to create communication across numerous devices. This makes it abundantly apparent that the slave will not initiate data; rather, it must wait until it is requested. Either serial buses or networks are used to facilitate master and slave communication between the devices. Modbus is positioned as the seventh layer in the OSI methodology. In order to supply the corresponding services mentioned by functioned codes, this first requests the protocol. These Modbus RTU function codes are part of the protocol’s request structure.
The delivery unit should start a device transaction in order to create the Modbus application data unit. This action alerts the server to do the designated kind of operation. The application protocol decides how the request that the master device initiates will be constructed. The function code will then be encoded with an 8-bit (or one byte) encoding. Only function codes in the 1 to 25 range are accepted, with 128 to 255 being reserved for unusual answers. This indicates that the function code field is what alerts the server to carry out the specified action when there is a request or message from master to slave. There will also be certain sub-functional codes for specific procedures. The master device, for instance, can read the ON and OFF transitions of a collection of multiple inputs and outputs. Moreover, it reads or writes data from a collection of Modbus registers. When the master receives the response from the slave, the slave uses the function code field to indicate whether the response is ordinary or extraordinary. The slave device will respond normally to the first function code’s request by resonating.
MODBUS SIMULATORS
Master Simulators
While creating a Modbus Slave device, a Modbus Master simulator can be a useful testing tool to access data from devices. There are many Master simulators that are easily accessible, including free, open source, and paid software.
Slave Simulators
While building up a test process for a device that is being built, a Slave simulator, which offers data for a Modbus Master, might be helpful as a known source of data. As a development specification and a source of anticipated behaviour for verifying a new device under development, a slave simulator can also be used to build a model of the latter.
Modbus RTU Slave Simulator (Unslave)
Modbus RTU simulator is a console programme that enables it to mimic as many Modbus RTU slaves or devices as necessary for testing and troubleshooting. Several types of tests are just not feasible without a dependable tool to emulate Modbus devices.
Current solutions often involve manual GUI-based setup. This means that in order to significantly alter the simulation, we must perform numerous tiresome manual tasks. This is inappropriate for automated testing. Unslave employs JSON configuration files as opposed to GUI-based configuration. JSON offers us a tonne of advantages:
- Easily modifiable in any text editor.
- Well-structured and legible at a glance.
- Direct documentation within the file.
- Copy-and-paste configuration.
In its working directory, Unslave by default loads the config.json configuration file. You can either change it or make a new.json file and specify its file location when running Unslave to use a different configuration.
The capacity to log each incoming and outgoing Modbus frame is an additional capability we require. This is helpful for troubleshooting protocol and master behavior issues. Unslave logging features consist of:
- Accessing console
- Various log verbosity
- Logging text documents