stephane / libmodbus

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

modbus_get_socket always return -1 #630

Closed audi0615 closed 1 year ago

audi0615 commented 2 years ago

Hi.

I'd like to inquire the amount of data available at a serial port using "ioctl". something like this.

int nread; ioctl(Serial, FIONREAD, &nread);

this is for implementing a non-blocking RTU slave but modbus_get_socket(ctx) always return -1. how can i get socket (file descriptor) of a serial port??

stephane commented 1 year ago

That's because the socket is not properly open, did you check the return code of modbus_connect?