stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

3.1.6: rapid-fire modbus_read/write_registers() sometimes returns -1 with invalid errno #600

Closed akohlsmith closed 3 years ago

akohlsmith commented 3 years ago

I have a simple C program which opens a connection to a device and then rapidly (every 20msec) issues

modbus_read_registers(mb, 9, 8, buf); modbus_write_registers(mb, 5, 2, buf);

I am checking the return code every time, and this can run for many minutes without any issue. Every now and again though, I get a return code of -1 and errno is set to the strange value 112345691 (0x06b2425b). I haven't found this value in the code, and it's consistently always this specific value.

I've checked to make sure I'm not calling anything between the libmodbus call and the return value/errno check.

I'm running this on osx 10.15.7 with libmodbus 3.1.6 from homebrew. I also don't see anything weird in a tcpdump capture of the traffic on that network port.

akohlsmith commented 3 years ago

Closing: I'm an idiot and somehow failed to read the "error handling" section on the main page. 🤦‍♂️