debevv/nanoMODBUS

Access to "Unit Identifier" byte in NMBS_TRANSPORT_TCP mode is impossible

arhiv6 opened this issue · 4 comments

I wanted to use the library for creation modbus TCP to RTU gateway. But in the library impossible get access to "Unit identifier" byte. In function recv_msg_header() I see reciveing this byte: nmbs->msg.unit_id (this string), but I can't access this field from outside the library.

I find only one variant: I can use sometsing like as

nmbs_set_platform_arg(&nmbs, (void *) &nmbs);

before calling nmbs_server_poll(&nmbs) and

nmbs_t *nmbs = (nmbs_t *) arg;
uint8_t unit_id = nmbs->msg.unit_id;

in my server request callbacks. But the documentation says:

All struct members are to be considered private, it is not advisable to read/write them directly.

It is only way?

This was a bit of an oversight, it doesn't make sense to not expose the RTU unit ID in server callbacks. Can you try this branch https://github.com/debevv/nanoMODBUS/tree/unit_id_callback and check if it's enough?

Yes, that's enough.

Fixed in cbd4fa6