Multipleve on one COM-port

30 views
Skip to first unread message

Kot Shrodingera

unread,
Jan 4, 2018, 3:04:21 AM1/4/18
to libmodbus
How can I make ModBus RTU slave answer qeries for two diefferent slave addresses using two different mappings?

Patrick Boettcher

unread,
Jan 4, 2018, 5:24:29 AM1/4/18
to Kot Shrodingera, libm...@googlegroups.com
Hi

Afaics this is currently not possible with upstream libmodbus

I implemented a callback-based modbus_reply()-mechanism which allows
you to handle multiple slaves with one libmodbus-instace. The callbacks
called by libmodbus in this implementation contain the slave-id and let
you decide which device needs to be handled:

See here

https://github.com/pboettch/libmodbus/tree/modbus-reply-callback

best regards,
--
Patrick.

Kot Shrodingera

unread,
Jan 4, 2018, 9:35:25 PM1/4/18
to libmodbus
Thanks. Can you give me an example of multi-slave implementation?

четверг, 4 января 2018 г., 16:24:29 UTC+6 пользователь Patrick Boettcher написал:

Patrick Boettcher

unread,
Jan 9, 2018, 12:18:03 PM1/9/18
to libm...@googlegroups.com
Hi,

On Thu, 4 Jan 2018 18:35:25 -0800 (PST)
Kot Shrodingera <kot.shr...@gmail.com> wrote:

> Thanks. Can you give me an example of multi-slave implementation?

I have several nice examples which I cannot yet publish - however they
are not using mappings anyway.

The libmodbus-mapping-implementation is based on the
callback-mechanisms (in my branch) which shows how you could handle it:

https://github.com/pboettch/libmodbus/blob/modbus-reply-callback/src/modbus-reply-mapping.c

You can copy this code and adapt it to your needs.

One solution could be to use the slave-id (which is passed to each
callback-function) to select the right mapping which you have allocated
during your initialization phase.

Using the callbacks you don't need to use mappings. Maybe using
something else to retrieve and store values would be more appropriate.

HTH,
--
Patrick.
Reply all
Reply to author
Forward
0 new messages