Simulate RTU device for testing

413 views
Skip to first unread message

Thomas Kelly

unread,
May 5, 2017, 11:00:43 AM5/5/17
to modbus-tk
Hi,

I've looked around for various modbus libraries that can simulate a serial device and this appears to be the best! I don't have a serial device to test on so I'm looking to simulate this device being connected, in order to simply add a register and a coil to a slave server with master server to read and write to them. Using the example simulator that comes in the examples on Github (https://github.com/ljean/modbus-tk/blob/master/examples/mysimu.py), I'm executing this using the port '/dev/ptyp5' as in the example and receiving a server error 'Error 13: permission denied' response. When trying to simulate a device, can I use any name in the '/dev/' folder? I've tried changing to another that is present in that folder such as '/dev/ttyS0' and set the permissions the read/write over all users with the same response. I've also changed the permissions of the simulating python script to the maximum (777) with no luck. I am working on an Ubuntu 1604 machine.

Execution:

tom@tom-OptiPlex-9020:~/scripts$ python simulator.py
'quit' for closing the server
server error: [Errno 13] Permission denied
modbus_tk.simulator is running...


 ps aux
tom       6288  0.2  0.1 190024 11724 pts/3    Sl+  15:43   0:00 python simulator.py


As shown above I can see  the process when it is running. When trying to add a slave to the '/dev/ptyp5' device as expected:
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ptyp5: [Errno 2] No such file or directory: '/dev/ptyp5'
 
Is it possible to simulate a RTU device that I can add coils and registers to, as if there were an actual serial device attached?
I'm aware some of this might seem a little basic and am just trying to get these examples running in this way as a start.

Thanks in advance,

Tom
simulator.py

Luc Jean

unread,
May 5, 2017, 11:11:06 AM5/5/17
to modb...@googlegroups.com
Hello Thomas,

I think that your Linux user doesn’t have any permission for accessing the /dev/ folder right? Does a `ls /dev`work?

May be you need to `sudo` to an admin user to run the script, or to give access to /dev/ to the current user?

I hope it helps

Best
luc 

--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<simulator.py>

Thomas Kelly

unread,
May 5, 2017, 12:04:05 PM5/5/17
to modbus-tk
Hi luc,

Thanks for the reply. Once I stuck sudo in front the simulator.py script runs as intended! Although the device simulated (/dev/ptyp5) does not appear in '/dev', is this normal?


root      6678  0.0  0.0  55040  3984 pts/3    S+   16:50   0:00 sudo python simulator.py

Secondly as expected with the device not being in '/dev', when I run the slave example (attatched) it also cannot find the device.

Kind regards,

Tom
rtuslave_example.py

Thomas Kelly

unread,
May 17, 2017, 8:56:59 AM5/17/17
to modbus-tk
For those interested,

I solved this issue by using a null modem emulator and set up simulated ports as guided here.
Reply all
Reply to author
Forward
0 new messages