Non-blocking server using libmodbus

1,682 views
Skip to first unread message

Chris Rice

unread,
Apr 19, 2013, 4:07:37 PM4/19/13
to libm...@googlegroups.com

Hello, I wonder if you experts can confirm my observations on a certain aspect of libmodbus;

The function "modbus_tcp_listen" blocks (ie suspends execution waiting for external event).  There is no built-in method to avoid this (eg listen in the background) in libmodbus.  The typical way to deal with this is to put the MODBUS server calls on a different thread, and you must do this in your application.

Also, the "modbus_tcp_listen" function will only establish/manage a connection with one remote client at a time.  If you want multiple clients to connect/read simultaneously, it is not straightforward (I think I saw a posting or sample code on this and it was fairly complex).

Any comments, thoughts, corrections?  Or is that about right.

These are not complaints, just observations and making sure I don't go off and do a lot of work on something that could have been done in a simpler way.

Thanks a lot for any help.

Chris

Stéphane Raimbault

unread,
Apr 20, 2013, 3:51:41 AM4/20/13
to libm...@googlegroups.com
Hello Chris,

2013/4/19 Chris Rice <chris....@gmail.com>


Hello, I wonder if you experts can confirm my observations on a certain aspect of libmodbus;

The function "modbus_tcp_listen" blocks (ie suspends execution waiting for external event).  There is no built-in method to avoid this (eg listen in the background) in libmodbus.  The typical way to deal with this is to put the MODBUS server calls on a different thread, and you must do this in your application.

Yes that's the way to use it. libmodbus focus on Modbus protocol and don't intend to provide a network framework.
 

Also, the "modbus_tcp_listen" function will only establish/manage a connection with one remote client at a time.  If you want multiple clients to connect/read simultaneously, it is not straightforward (I think I saw a posting or sample code on this and it was fairly complex).

I wrote a simple example of that (many connections at once but only one thread)

I never published the multi-threads version of this program (one thread by connection).

Stéphane 

Reply all
Reply to author
Forward
0 new messages