Problems with function modbus_strerror(errno).

37 views
Skip to first unread message

Camilo Andrés

unread,
Jun 3, 2016, 4:09:10 PM6/3/16
to libmodbus
Hello everyone. 
I'm using libmodbus with "Visual Studio 2013". I have a problem. When I use the "modbus_strerror (errno)" method to print the error message, I always get the message "No error", because the value of "errno" is not updated.

The library functions "LibModbus" are executed correctly; the downside is when there is an error (in connection or polling), the message I get is: "No error"
I've used in the following examples in C ++:
_______............._______________
modbus_t * channel;
...

this-> statusChannel = modbus_connect (this-> channel);

if (this-> statusChannel == -1)
{
msg.clear ();
msg = "Connection failed:" + (string) modbus_strerror (errno);

cout << std :: endl << msg;

modbus_free (this-> channel);
}
___________........................___________

uint8_t * tab_rp_bit = new uint8_t [numberAddresses];

int rc = modbus_read_bits (channel, StartAddress, numberAddresses, tab_rp_bit);

if (rc == -1)
{
msg.clear ();
msg = "Error reading" + to_string (numberAddresses) + "Coil Status from address" + to_string (StartAddress) + ":" + (string) modbus_strerror (errno);
cout << std :: endl << msg;


}
___________________.....................__________

I always use en my files:

#include <stdio.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <errno.h>
Reply all
Reply to author
Forward
0 new messages