Author Topic: Modbus Master and Modbus Slave Simulator apps  (Read 11096 times)

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Modbus Master and Modbus Slave Simulator apps
« on: November 30, 2019, 09:20:19 PM »

Offered AS IS.
Intended as a quick testing tool.
Can be tested as they are, see reply #3.


Moved here from the other category and topic (https://www.advancedhmi.com/forum/index.php?topic=765.15) for better visibility.

Both apps are based on modified nModbus .NET 3.5 libraries, Copyright (c) 2006 Scott Alexander ( https://code.google.com/p/nmodbus/ ).
Licensed under MIT license ( http://opensource.org/licenses/mit-license.php ) and included in the Project.


Modbus Slave Simulator

This is a new version of the Modbus Slave Simulator previously discussed in the topic mentioned above.

Now supporting RTU, TCP, UDP and ASCIIoverRTU protocols.

For RTU/ASCIIoverRTU protocols, on a single PC, AHMI can communicate with this simulator with the help of the tty0tty (Linux) / com0com (Windows) program which would provide virtual serial port pairs.

Since the DataGridView controls, used to display boolean/register values within the simulator window, seem to require rather fast computer, all instances were limited to initially have only 20 rows showing thus limiting the number of visible addresses (which should still be sufficient for simulation but can be changed and increased via the "Row Count" combo box). This has improved the speed of loading of the program in Mono on slower PCs.

The simulator will still accept ALL the Read/Write requests for ALL the registers and keep the values stored in the slave's dataStore. They will just not be visible in the data grid view, unless you choose to have all the rows visible.

There is also a TextBox added to allow for manual input of the serial port to be used (intended for Linux so tty0tty virtual ports could be accessed).

All the simulation was tested in:
- Windows 7/10
- Kubuntu 14.04 Linux on an old HP TC1100 Tablet PC, with 1.2GHz Pentium-M CPU and 1.25GB RAM.
- Raspbian Buster on RaspberryPi 2

The library supports Masked Bit Write, function code 22 (0x16H).


Modbus Master

It has the library built in support for RTU, TCP, UDP, RTUoverTCP, RTUoverUDP, ASCIIoverRTU, ASCIIoverTCP and ASCIIoverUDP protocols (not all of them were tested).

It also supports F, L, U, UL and S modifiers as well as bit/character Reading/Writing.
For bit/character operation, you can select to have it either as consecutive bits/characters within a single element or the exact individual bit/character from each of the multiple elements.
Either a single value or the exact number of comma separated values will be required for writing if Points number > 1.

A support for 64-bit values was added - Double (Float64), signed and unsigned Integer64 (Long and ULong).
Modifiers of FQ, LQ and UQ were added to the Master app, where "Q" stands for Quad Word.

A support for 128-bit values was added - signed and unsigned Integer128.
Modifiers of LO and UO were added to the Master app, where "O" stands for Octa Word.

SwapWords option, if enabled, might present a challenge for some devices since these things don't seem to be officially defined.
Just try either of the 3 options provided for 64-bit values word order or any of the 7 options provided for 128-bit values word order (theoretically, there should be far more than 7 options available but I didn't bother going through all of them).

The library supports Masked Bit Write, function code 22 (0x16H), but the app also includes the built-in code for slave devices that don't support FC22.
The built-in code will read register - modify the bit - write register, which could affect the bit values that changed during this operation.
Either of these apply to all values (16-bit, 32-bit, 64-bit, 128-bit).

Addresses do NOT have offset of +1.

The "Auto" checkbox allows for Automatic Readings with poll interval specified in the "Interval" box.
If you add a new address to read after the "Auto" box is checked then you will have to uncheck it and check it again.

It is intended for quick testing but always try using AdvancedHMI as a Modbus Master instead, since it offers far more features and functionality.

Read the comments inside the form and also hover the mouse over the labels since most of them do provide hints.


This post has VB Master solutions attached (for Windows and Mono).
« Last Edit: January 20, 2021, 04:26:07 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #1 on: November 30, 2019, 09:21:35 PM »
This post has VB Slave solutions attached (for Windows and Mono).

« Last Edit: July 06, 2020, 11:49:36 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #2 on: November 30, 2019, 09:24:24 PM »
This post has VB Windows exe files attached.

You will get the same files if you use solutions from previous posts.

« Last Edit: September 28, 2020, 02:19:04 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #3 on: November 30, 2019, 09:25:47 PM »
This post has the picture of Master & Slave attached (communicating over TCP).

The yellow boxes indicate bit/character read or write mode.

« Last Edit: September 28, 2020, 02:33:03 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #4 on: June 04, 2020, 09:47:05 PM »
This post has C# solutions for Windows of both apps.

Let me know if you find any bugs.

« Last Edit: December 21, 2020, 04:00:32 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #5 on: June 04, 2020, 09:50:06 PM »
This post has the C# exe files of both apps for Windows.

You will get the same files if you use the solutions from the previous post.

« Last Edit: December 21, 2020, 04:00:57 AM by Godra »

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #6 on: October 03, 2020, 09:00:11 PM »
Hey Godra, I am interested in creating a Modbus simulator to simulate several of the same type of device on a single PC where I would need to channel registers to a specific IP address saved in the PC's IP configuration.  For instance IP#1 and IP#2 would each need register 40001 but of a different value.  Can your app do this or do you know if the nModbus library can accomplish this?  Thank you.   

Godra

  • Hero Member
  • *****
  • Posts: 1449
    • View Profile
Re: Modbus Master and Modbus Slave Simulator apps
« Reply #7 on: October 03, 2020, 10:59:29 PM »
You can run multiple instances of this master or slave simulator and assign different IP addresses to each.

MODRSsim2 simulator can have each of its stations be assigned different set of registers but all under the same IP/Port (see the attached picture). It will also allow you to run multiple instances of it on different ports and it could possibly use multiple ethernet interfaces built into your computer (if you have those available).

NModbus is just a library so it might do what you need but you would have to be inventive.
« Last Edit: October 03, 2020, 11:02:37 PM by Godra »