stephane / libmodbus

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

modbus_receive() function returns -1 on USB serial port (TTL level) devices #754

Open ZhiyuanYuanNJ opened 2 weeks ago

ZhiyuanYuanNJ commented 2 weeks ago

The following is the debug report: .\RemoteGPIOControl.exe : ERROR timed out: select 所在位置 行:1 字符: 1

My Code Process:

// init 
modbus_new_rtu
modbus_mapping_new_start_address
modbus_set_slave
modbus_connect
do {
    ret = modbus_receive(MBInfo.mb, query);     //always return -1
    printf("ret == %d\n", ret); 
      } while (ret == 0);
.....
ZhiyuanYuanNJ commented 2 weeks ago

It may be related to the device's driver used. I will replace the original manufacturer driver with a CDC driver and the function did not return -1 did not return -1. But I want to know the reason, because this vendor's driver has no problem using it.