Author Topic: Modbus TCP Simulation in Linux  (Read 7609 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Modbus TCP Simulation in Linux
« on: September 08, 2019, 10:59:39 PM »
To test AHMI in Linux environment, one can use ModbusPal java simulator, found here:

https://sourceforge.net/projects/modbuspal/files/modbuspal/RC%20version%201.6b/

I would suggest to just follow these steps:

1) Create AHMI folder inside the Home folder
2) Download ModbusPal.jar file to AHMI folder
3) Copy your project's Debug folder to AHMI folder
4) Open Terminal window and run commands to open ModbusPal (as the 1st picture shows)
5) Configure and run the ModbusPal simulation (as the 2nd picture shows):
---- Add one or more slaves
---- Add Holding registers and Coils to each slave
---- Click the "Run" button
6) Open another Terminal window and run commands to open AHMI window (as the 3rd picture shows)
---- AHMI should be configured to use the ModbusTCP driver with 127.0.0.1 address and 502 port

It's probably the easiest to use the pop up Keypad of the BasicLabel controls to change Holding registers and Coils values but you can also use the ModbusPal window to do this as well (the editor window that shows Holding registers and Coils and has "Stay on top" checkbox).

This was tested in Kubuntu 14.04 but should work in other distributions for as long as Java and Mono are installed (possibly on Raspberry Pi too).

There is an option in ModbusPal for Serial communication but is disabled until your Linux installation has RXTX java library installed and configured properly. Here is what worked in Kubuntu:

1) Use Package Manager to install librxtx-java package, which is Full Java CommAPI implementation from Sun for Serial/Parallel/RS485/Raw communication, but we will just observe Serial part.

---- this installation will only copy the following files to kind of wrong location:
RXTXcomm.jar ---> in folder /usr/share/java/
librxtxSerial.so ---> in folder /usr/lib/jni/

---- here is where they need to be so things work:
RXTXcomm.jar ---> <JAVA_HOME>/jre/lib/ext
librxtxSerial.so ---> <JAVA_HOME>/jre/lib/i386/

One could use the following command to see Java parameters including JAVA_HOME: java -XshowSettings:properties.
I ended up adding the following line to /etc/environment: JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386"

2) Copy the files:

sudo cp /usr/share/java/RXTXcomm.jar /usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/RXTXcomm.jar
sudo cp /usr/lib/jni//librxtxSerial.so /usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/librxtxSerial.so

The 4th picture shows the Serial tab of ModbusPal.

Resource: http://java-buddy.blogspot.com/2013/06/setup-rxtx-jar-and-so-for-ubuntu.html
« Last Edit: September 11, 2019, 11:54:12 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus TCP Simulation in Linux
« Reply #1 on: September 21, 2019, 02:16:25 AM »
There is also another simulator which can be used for either of Modbus RTU, TCP, UDP or ASCIIoverRTU simulation under Mono environment in Linux.
This might be a better choice of a simulator all together since the installation is a bit more straightforward.

It was discussed here:

https://www.advancedhmi.com/forum/index.php?topic=765.15

and a full solution can be found here:

https://www.advancedhmi.com/forum/index.php?topic=2567.0

The attached pictures show AHMI communicating simultaneously with 2 instances of this simulator, for RTU & TCP channels.
tty0tty program was used to create virtual serial port pair for RTU communication and can be found here:

https://github.com/freemed/tty0tty

This was tested in Kubuntu 14.04 and Raspbian Buster but should work in other distributions for as long as Mono is installed.

See the next post for additional info.
« Last Edit: June 10, 2020, 12:51:46 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Modbus TCP Simulation in Linux
« Reply #2 on: September 21, 2019, 02:22:06 AM »
The picture attached here shows how to run AHMI from the Debug folder and 2 Modbus simulators from the Release folder.

For RTU/ASCII communication, tty0tty needs to be installed first and then just use "/dev/tnt0" in the simulator and "/dev/tnt1" in the AHMI.

Also attached are the "Release" folders for Master & Slave, which can be used directly but the full solutions can be used to make any additional modifications.


Some other FREE simulators (not tested by me):

   https://www.openplcproject.com/
   https://hmisys.com/
« Last Edit: July 19, 2020, 09:39:04 PM by Godra »