Usage of Modbus RTU Master and Modbus RTU Client simultaneously

Hello,

We want to use a nrf52840 as a logic controller which reads data from Modbus RTU Sensors (as Modbus RTU Master) and simultaneously is the Modbus RTU Server for an higher unit, which reads calculated values and process values from a bunch of nrf52840-devices. When trying to implement both in one application, by enabling both roles in the conf, some functions of the master implementation become undefined:

CONFIG_MODBUS=y
CONFIG_MODBUS_ROLE_CLIENT=y
CONFIG_MODBUS_ROLE_SERVER=y
 

c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `main':
C:/path/to/the/project/workspace/evaldemo/src/main.c:281: undefined reference to `modbus_read_holding_regs'

When using only one role at a time, the sample works fine.

Is there a way to use both roles in one application? (of course on different interfaces, therefore we choose the nrf52840 instead of the nrf52832, which only has one UART interface)

Thank you!

BR Thomas

Parents
  • Hi!

    I took a look at the configs.

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/subsys/modbus/Kconfig#L17

    Looks like if you want both client and server, you should not set CONFIG_MODBUS_ROLE_CLIENT and CONFIG_MODBUS_ROLE_SERVER. But instead set CONFIG_MODBUS_ROLE_CLIENT_SERVER=y

  • Hi, I would like to implement  the same. I tried the above recommendation with the client and server examples from Nordic on 2X  nRF52840 DK, one for client and 2nd one for the server.  I changed to CONFIG_MODBUS_ROLE_CLIENT_SERVER = y.  Both the Client and sever examples worked.

    Now I would like to add the server capabilities to the client. Primarily the callback functions needs to be registered so that when the 2nd client sends a message, it is processed. How do we do this?

    If I tried to initialize the server, modbus_init_server, after initializing the modbus_init_client  using the same iface, the server does not get initialized for obvious reasons - because it the same uart1 interface. The interface is already used.

    Looking at the code from modbus_init_server(iface, param) and the modbus_init_client(...) and comparing, they are identical,  except that the server include modbus_user_fc and registering the callback functions.

    I did search for a combination call back and could not find.

    Can you please help?

    Thanks.

Reply
  • Hi, I would like to implement  the same. I tried the above recommendation with the client and server examples from Nordic on 2X  nRF52840 DK, one for client and 2nd one for the server.  I changed to CONFIG_MODBUS_ROLE_CLIENT_SERVER = y.  Both the Client and sever examples worked.

    Now I would like to add the server capabilities to the client. Primarily the callback functions needs to be registered so that when the 2nd client sends a message, it is processed. How do we do this?

    If I tried to initialize the server, modbus_init_server, after initializing the modbus_init_client  using the same iface, the server does not get initialized for obvious reasons - because it the same uart1 interface. The interface is already used.

    Looking at the code from modbus_init_server(iface, param) and the modbus_init_client(...) and comparing, they are identical,  except that the server include modbus_user_fc and registering the callback functions.

    I did search for a combination call back and could not find.

    Can you please help?

    Thanks.

Children
Related