Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with initializing the registers in the server #615

Closed
ram469 opened this issue Dec 22, 2021 · 4 comments
Closed

Issues with initializing the registers in the server #615

ram469 opened this issue Dec 22, 2021 · 4 comments

Comments

@ram469
Copy link

ram469 commented Dec 22, 2021

Hi,

I am using the below statement to create a memory with different start addresses.

modbus_mapping_t *mb_memory_section;
mb_memory_section = modbus_mapping_new_start_address(start_bits, nb_bits, start_input_bits, nb_input_bits, start_registers, nb_registers, start_input_registers, nb_input_registers);

then I tried to initialize this memory like below
mb_memory_section ->tab_registers[ start_registers ] = 555;
I tried to get the value using the client at start_registers address but it is zero.

Worked case:
When I initialized the memory like below it is working
mb_memory_section ->tab_registers[0] = 555;
I tried to get the value using the client at this start_registers address and it is 555

Is this the expected behavior? or a bug.

Hardware: NVIDIA Jetson Xavier NX board
OS: Ubuntu
libmodbus version: latest (built from sources)

Thanks,
Ramakrishna

@stephane
Copy link
Owner

stephane commented Jan 8, 2022

What value do you use for start_registers?
How many registers did you allocate?

@ram469
Copy link
Author

ram469 commented Jan 18, 2022

Hi Stephane,

Sorry for the late reply, I use any random value rather than 0 and <= 65535. I have allocated 10 registers.

Thanks,
Ramakrishna

@stephane
Copy link
Owner

The next documentation will include a better explanation:

The different starting addresses make it possible to place the mapping at any
address in each address space. This way, you can give access to the clients at
values stored at high addresses without allocating memory from the address zero,
for eg. to make available registers from 340 to 349, you can use:

mb_mapping = modbus_mapping_new_start_address(0, 0, 0, 0, 340, 10, 0, 0);

The newly created mb_mapping will have the following arrays:

  • tab_bits set to NULL
  • tab_input_bits set to NULL
  • tab_input_registers allocated to store 10 registers (uint16_t)
  • tab_registers set to NULL.

The clients can read the first register by using the address 340 in its request.
On the server side, you should use the first index of the array to set the value
at this client address:

mb_mapping->tab_registers[0] = 42;

@PlayaJay22
Copy link

I think your documentation has an error. parameter 5 and 6 are for holding registers, not input registers.
I think your documentation on libmodbus.org should be:

_The newly created mb_mapping will have the following arrays:

tab_bits set to NULL
tab_input_bits set to NULL
tab_registers allocated to store 10 registers (uint16_t)
tab_input_registers set to NULL._

Unless I'm missing something fundamental, but I've looked into your modbus.c code and it clearly shows parameters 5 and 6 are for nb_registers, NOT nb_input_registers

Please update the documentation because this is SUPER confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants