Modbus TCP Communication Errors

Asked by Nuno Santos

Hello Sirs,

I'm trying to read some registers from a energy meter with libmodbus and I always get one of the following errors:

- ERROR Communication time out (-12) --> most common
- ERROR Target device failed to respond (-11)

I checked modbus_param_t is Ok, modbus_connect function returns 0 but I got the errors above when I execute the
read_holding_registers funciton .

However, I can read the same registers with modpoll without any problem..

Do you have any ideia about what could be wrong?

Best Regards,
Nuno Santos

Question information

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

To have good exception/error handling I recommend you to use libmodbus 2.9.3, set the debug mode (see the documentation on libmodbus.org) to display a detailed modbus request.

Could you provide your modbus source calls too?

By curiosity, which energy meters do you use (you can answer in private to avoid advertising)?

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#2

Here is example where I'm getting the communication errors:

CODE:

      modbus_param_t mbParam;
      modbus_init_tcp( &mbParam, "10.192.10.60", 502);
      uint16_t data [24];
      if ( modbus_connect(&mbParam) > -1) {
  printf("\nDevice connected\n");
  int ret = read_holding_registers( &mbParam, 1, 0x513, 1, data);
  printf("\nreturn from reading: %d\n", ret);

 }else {
   printf("\nCould not connnect to device\n");
 }

OUTPUT:
      Device connected

      ERROR Target device failed to respond (-11)

      return from reading: -11

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

Could you provide all requested information, please?

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#4

Hello Stéphane,

I'm going to download the 2.9.3 version and then I can give you more info.
I already sent you a email about the energy meter.

Please tell me of you need some more information.

Thank you for your reply.

Best Regards,
Nuno Santos

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

Yes, I need to see the request trame (libmodus is able to show it) and the modpoll command used.

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#6

Here is the request made:
[00][01][00][00][00][06][01][03][05][13][00][01]

Modpoll command:
./modpoll -m tcp 10.192.10.60 -1 -a 1 -r 513 -t 4 -c 1

Modpoll response:
modpoll - FieldTalk(tm) Modbus(R) Polling Utility
Copyright (c) 2002-2006 FOCUS Software Engineering Pty Ltd
Visit http://www.modbusdriver.com for Modbus libraries and tools.

Protocol configuration: MODBUS/TCP
Slave configuration...: Address/Id = 1, start reference = 513, count = 1
Communication.........: 10.192.10.60, port 502
Data type.............: 16-bit register, output (holding) register table

Polling slave ...
[513]: 0

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

You seem to have confused hexadecimal and decimal address (0x513 is 1299 in your code source) and if this address isn't allow on your Modbus device it explains the problem. However your Modbus device is not Modbus compliant because the answer should be an exception in this case.

Revision history for this message
Nuno Santos (nuno-santos-vigiesolutions) said :
#8

Yes, I though that the value had to being passed into the function as hexadecimal. The error given leads me to look up around communication problems
Thanks for you support.

Best Regards