Read Data From modbus Struct

Asked by rtu-master

Hello,
my question about libmodbus is that: in libmodbus package there is a function that extract from the modbus response message only the number read from slave's register?

For example:

01 05 01 2A 62 6a 23

In that response 01 is the lenght of response, so I must extract 2A 62 and convert from HEX to INT or FLOAT.

Is possible to make that whit a funcion present in modbus.c ? Or there is an example code in C that make it?

Regards!

Question information

Language:
English Edit question
Status:
Answered
For:
libmodbus Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stéphane Raimbault (sra) said :
#1

Yes of course, there are a function specific to extract each type of data values:
- coil
- input
- registers
- etc

Just have a look to modbus.h (comments are included) or in tests/ directory for some examples.

Revision history for this message
rtu-master (abominio123) said :
#2

For example if I use that function:

int read_holding_registers(modbus_param_t *mb_param, int slave,
                           int start_addr, int nb, uint16_t *dest);

return me response from slave in the format 0105012A62 6a23

So, I do not view any other function in modbus.h that return me only the real value readed from registry (in this case 2A62 -> translated in int type for example).

Perhaps I do not understand or view where is the right function to use.

Revision history for this message
Stéphane Raimbault (sra) said :
#3

It's difficult to help w/o more information about the arguments you use (start_addr, nb, etc) and the value returned by the function.

2A62 is a just a value, you've certainly used printf with %x to see the result, try with %d to display a decimal value but at that point, you just need a book on C programming...

Can you help with this problem?

Provide an answer of your own, or ask rtu-master for more information if necessary.

To post a message you must log in.