Releasing Modbus RTU Simulator - Unslave
Today we are releasing our free Modbus RTU Slave Simulator. It's a console program that allows you to simulate any number of Modbus RTU devices/slaves for testing and debugging purposes. This tool is invaluable for us. Hopefully it will be useful for the community as well.
Why was Unslave Created?
We are doing a lot of testing and debugging of Modbus networks with different configurations. It really helps to have a reliable tool to simulate Modbus devices, otherwise some types of tests are simply impractical.
While there are existing Modbus simulators, we have found none of them satisfied all our requirements.
Open, Text-Based Configuration
Existing solutions usually use manual GUI-based setup. This means we need to do many tedious manual actions to significantly change the simulation. This is unacceptable for automated testing.
Instead of GUI-based configuration, Unslave uses JSON configuration files. The benefits of JSON for us are enormous:
- easily editable in any text editor
- well-structured, readable at a glance
- can be documented directly within the file
- can copy and paste configuration
By default, Unslave will load the configuration file named config.json
in it's working directory.
To use a different setup, you can either edit it, or create a new .json
file and specify it's file path when running Unslave:
unslave.exe alternative-setup.json
Modbus Frame Logging
Another feature we need is the ability to log all incoming and outgoing Modbus frames. This is useful for debuging errors in the protocol and behavior of masters.
Unslave logging capabilities include:
- logging to Console
- logging to text files
- different levels of log verbosity
Here's an example of a log file:
2017/06/06 17:21:54.310 - TRACE: Byte received: 1. Total: 1
2017/06/06 17:21:54.310 - TRACE: Byte received: 3. Total: 2
2017/06/06 17:21:54.310 - TRACE: Byte received: 0. Total: 3
2017/06/06 17:21:54.326 - TRACE: Byte received: 60. Total: 4
2017/06/06 17:21:54.326 - TRACE: Byte received: 0. Total: 5
2017/06/06 17:21:54.326 - TRACE: Byte received: 1. Total: 6
2017/06/06 17:21:54.342 - TRACE: Byte received: 68. Total: 7
2017/06/06 17:21:54.358 - TRACE: Byte received: 6. Total: 8
2017/06/06 17:21:54.363 - INFO: Modbus frame received: [1 3 0 60 0 1 68 6]
2017/06/06 17:21:54.363 - INFO: Reading value: 1HR60 = 14119
2017/06/06 17:21:54.363 - INFO: Modbus frame sent: [1 3 2 55 39 238 110]
As you can see, the log it informative and easy to understand. You can use our Modbus tutorial to find out the meaning of each frame.
To change log verbosity, edit the level
setting in logger.json
. To enable logging to file, set file
to true
:
{
"level":"trace",
"file":true
}
Possible log levels:
- trace - the most detailed log
- info - shows only the most important messages
- error - hides all messages except for errors
Portability
We wanted Unslave to be portable, meaning it doesn't require installation. You simply extract the archive, and run it. You can put it on a USD flash drive and run it on any PC in a few seconds.
Simulating a Modbus Slave Node
Now let's see what it's like to work with Unslave.
Here is an example configuration where one Modbus slave node is listening to COM1
:
{
"port": {
"name": "COM1",
"baudRate": 115200,
"dataBits": 8,
"parity": "none",
"stopBits": 1
},
"slaves": {
"1": {
"isOnline": true,
"registers": {
"HR0": 1,
"HR10": "0x0A",
"C0": true
}
}
}
}
We have specified the values of two holding registers: HR0
, HR10
and one coil: C0
.
Every other register will have the value of 0
or false
by default.
As per Modbus protocol, there are four types of registers:
- Coils (C)
- Discrete Inputs (DI)
- Holding Registers (HR)
- Input Registers (IR)
Simulating Modbus Exceptions
In order to simulate a Modbus exception response, use a configuration similar to this:
"1": {
"isOnline": true,
"registers": {
"HR0": 1,
"HR1": { exception: 4 }
}
}
This configuration means that any request to read or write Holding Register 1
will result in a Modbus Exception with code 4
. The code 4
means slave failure to respond.
Modbus TCP
Please see Using Unslave as a Modbus TCP server
Unslave API
Please see Unslave API guide to see how to update slave configuration at runtime via a RESTful HTTP API.
System Requirements
- Windows XP SP4 or greater
- .NET Framework 4.0
- Serial Port Access
- 2MB of disk space
Download
If you think Unslave could be useful for you, we have good news - it's free.
To download the latest version, please proceed to Unslave download page.