TCP server example

560 views
Skip to first unread message

gianca...@gmail.com

unread,
Sep 8, 2017, 6:28:11 AM9/8/17
to libmodbus
I have read the documentation and consult the examples (bandwitch-server-one.c) but there is something that I don't understand (my english is not good and google help me ... :) ).
How/when should I use the values ​​of my registers in library code?

My program manages 3 sets of registers
0-1000
5000-7000
10000-12000
all contain 2 bytes, reading and writing.

I understand that

1) I have to create a ctx = modbus_new_tcp ("127.0.0.1", 1502);
2) I put the socket in listen state socket = modbus_tcp_listen (ctx, 1);
3) I wait for accept connection modbus_tcp_accept (ctx, & s);
4) I allocate mb_mapping  mb_mapping = 
 modbus_mapping_new (MODBUS_MAX_READ_BITS, 0,
                                    MODBUS_MAX_READ_REGISTERS, 0);

5) Receive the request rc = modbus_receive (ctx, query);

6) Respond with modbus_reply (ctx, query, rc, mb_mapping);
7) Free the resources

ok? But when/where should  I use the values of my registers ​​0-1000 / 5000-7000 etc.?
I'm sure this is a stupid question, thank you for your time

gianca...@gmail.com

unread,
Sep 11, 2017, 3:31:52 AM9/11/17
to libmodbus
I read another example (unit-test-server.c), the solution is in mb_mapping->XXX

  /* Initialize values of INPUT REGISTERS */
    for (i=0; i < UT_INPUT_REGISTERS_NB; i++) {
        mb_mapping->tab_input_registers[i] = UT_INPUT_REGISTERS_TAB[i];;

Stéphane Raimbault

unread,
Sep 11, 2017, 5:19:21 AM9/11/17
to libm...@googlegroups.com
Yes you can access the data via mb_mapping->tab_input_registers pointer. The documentation isn't very clear on that subject.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "libmodbus".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages