Support for MODBUS RTU over TCP?

5,181 views
Skip to first unread message

George Pajari

unread,
Jun 16, 2012, 9:22:16 AM6/16/12
to libm...@googlegroups.com
Is there a method to support MODBUS RTU over TCP? By this I mean sending RTU-type MODBUS packets (including slave ID and checksum) over TCP to an Ethernet-to-Serial converter connected to a MODBUS RTU slave?

If not, I'm game to add the support to the code, just don't want to re-invent the wheel if someone else has done it.

Thanks.

Torello Querci

unread,
Jun 26, 2012, 2:46:51 AM6/26/12
to libm...@googlegroups.com
Hi George.

I have this configuration on production. ù
Unfortunally libmodbus is not able to manage directly tcpip/serial
converter and I think that this is right.
In order to comunicate with the ethernet/serial converter I use the
tibbo driver downloaded from here
http://tibbo.com/downloads/soi/vspdl.html
Using this driver I able to see the remote serial port as local serial
port (device /dev/vsps0, /dev/vsps1 ....) and now I can use the
libmodbus to
get and set register values.

I not know if this driver is compatibile with your device.


Best Regards,
Torello Querci

2012/6/16 George Pajari <george...@gmail.com>:

George Pajari

unread,
Jul 3, 2012, 3:52:32 AM7/3/12
to libm...@googlegroups.com
Thanks for that suggestion.

I wanted a cleaner approach that did not require a device driver. This would also let me use very inexpensive TCP-to-Serial devices that do not have Linux driver support such as the Wiz1000 (see wiznet.co.kr/wiz1000) which is what I'm using in my test lab (and will shortly deploy into the field).

Since the fundamental difference between MODBUS RTU over serial comms and MODBUS RTU over TCP is simply the communications medium, I thought it would be relatively straightforward to add this feature to libmodbus, but when I started on the project little did I realise that the exceptionally clean design and beautifully designed libmodbus would make the work trivial.

All I had to do was copy and paste existing code to create a new function:
     modbus_t* modbus_new_rtutcp(const char *ip, int port)
and everything worked as expected first time. I only had to write three lines that were not pure copy and paste.

Kudos to Stephane Raimbault!

I have not had a chance to test the code very much and so will wait until I have had a chance to do so before posting it (and passing it on to Stephane). If anyone is in a hurry to get it, please write to me directly.


On Monday, June 25, 2012 11:46:51 PM UTC-7, Torello Querci wrote:
Hi George.

I have this configuration on production. ù
Unfortunally libmodbus is not able to manage directly tcpip/serial
converter and I think that this is right.
In order to comunicate with the ethernet/serial converter I use the
tibbo driver downloaded from here
http://tibbo.com/downloads/soi/vspdl.html
Using this driver I able to see the remote serial port as local serial
port (device /dev/vsps0, /dev/vsps1 ....) and now I can use the
libmodbus to
get and set register values.

I not know if this driver is compatibile with your device.


Best Regards,
Torello Querci

2012/6/16 George Pajari:

George Pajari

unread,
Jul 3, 2012, 3:54:09 AM7/3/12
to libm...@googlegroups.com
Thanks for the suggestion...Ihave replied to the list.

g.

Xuan Glez

unread,
Nov 26, 2012, 12:39:53 PM11/26/12
to libm...@googlegroups.com
Hi George

Then have you a functional modification for tcp-rtu? I'm looking for that, could you tell me how did you that? changes in constructor/destructor? or a entire new class?

Thank you

Johan Englund

unread,
Jan 29, 2013, 11:54:36 PM1/29/13
to libm...@googlegroups.com

I'm attaching my patch against libmodbus 3.0.3 to get RTU over TCP. Just use the new function modbus_new_rtutcp(...) to create your modbus context, all else is business as usual.

Observe that this is an ugly patch that breaks the design guidelines of the beautiful original code. I have a customer hanging over my shoulder waiting for results so I didn't have time to prettyfi it (as usual).

Best regards,
Johan
libmodbus-3.0.3_rtu_tcp_patch.txt

Xuan Glez

unread,
Jan 30, 2013, 3:21:02 PM1/30/13
to libm...@googlegroups.com
Thank you! I'll try it very soon, Im using now a weird virtual com app for use my app with libmodbus (I agree with you, beautiful code), and this could help me a lot, and save very much time (I have a customer over my shoulder too :) ).

Best regards

Xuan
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes libmodbus.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 

Michael Huang

unread,
Mar 2, 2013, 2:41:49 AM3/2/13
to libm...@googlegroups.com
Hi Johan,

I'm working on a project and it needs modbus RTU over TCP. So I am very happy to see your patch code. 
I have added your patch code but I still have difficulty to send modbus TCP message with (ip, port, baud_rate, dev_addr, reg_no, nb) to the modbus TCP/RTU gateway. I am wondering whether you have sample code like the random-test-server and random-test-client can be referenced. or any working sample code for reference. Thank you very much in advance.

Best Regards,
Michael

Daniel Villanueva

unread,
Nov 9, 2013, 7:06:34 AM11/9/13
to libm...@googlegroups.com
Hi,

I have been reading this thread in order to solve the same problem: modbus RTU over TCP. In my case I am using GNU/Linux and I need to connect to a RTU modbus device through a RS485/ethernet adapter.

After considering several possibilities, the solution I have adopted is using a virtual serial port redirected to a TCP socket by means of socat tool. This tool generates a virtual device that accepts configuration ioctls  in the same way as a serial port device and it can redirect data to a TCP socket. 

Creating the virtual serial device is simple, just install the socat tool (or package for your distribution) and launch it:
socat TCP4:<ip_for_rs485_ethernet_adapter>:<port> PTY,link=<path_for_virtual_device_to_generate> &

With this execution socat is creating a virtual serial device in the path indicated. If now you use your RTU modbus solution over this virtual serial device the RTU modbus data is sent to the modbus device over the TCP socket and then over the RTU modbus bus.

In my case it worked like a charm without any modifications in modbus library (I am using libmodbus).

Hope this helps to anyone.

Best regards.

Xuan Glez

unread,
Apr 24, 2014, 6:40:47 AM4/24/14
to libm...@googlegroups.com
I forgot to say, I tried the patch and works perfectly, now I can access to rtu devices across rs485-ethernet converter without make virtual com ports.

Thank you !!!

Ladrans Ladrans

unread,
Jun 29, 2015, 8:29:45 PM6/29/15
to libm...@googlegroups.com, george...@gmail.com
Dear George,

I am interested in your solution regarding rtu over tcp. 
I am currently developing a modbus tool for OS X and as library i am using libmodbus as well. 
I have to adapt the possibility of communication RTU over TCP. Therefore i need your solution.
Can you please share with me your codes, so that i can use the same for my modbus tool as well. 

Thanks and
Kind regards.
MK

3 Temmuz 2012 Salı 11:52:32 UTC+4 tarihinde George Pajari yazdı:

hanswu...@gmail.com

unread,
Jul 29, 2016, 10:09:21 AM7/29/16
to libmodbus


Am Mittwoch, 30. Januar 2013 05:54:36 UTC+1 schrieb Johan Englund:

I'm attaching my patch against libmodbus 3.0.3 to get RTU over TCP. Just use the new function modbus_new_rtutcp(...) to create your modbus context, all else is business as usual.


Hi Johan,
your patch is quite a few days old, but apparently there is not much of an alternative. I´ve got the a real Device running with your patch. I fail to emulate the device though. Connection seems to be established fine, however if I try to read from the registers I hit a timeout. Have you been successfull in running a slave with you patch?

Roberto Walles

unread,
Apr 26, 2017, 9:18:30 AM4/26/17
to libmodbus, george...@gmail.com
Hello, here is an article about Modbus RTU over Ethernet  that I've found

Have anybody tested this software?


Reply all
Reply to author
Forward
0 new messages