Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZhiyuanYuanNJ opened this issue Jul 6, 2024 · 1 comment

Comments

@ZhiyuanYuanNJ
Copy link

  • Which operating system are you using?
    Windows 10 x64

  • Describe the exact steps which reproduce the problem in as many details as
    possible. For example, the software/equipment which runs the Modbus server, how
    the clients are connected (TCP, RTU, ASCII) and the source code you are using.
    Modbus RTU
    I'm using modbus rtu, my code runs fine on a virtual serial port, but when I change the serial port to an actual TTL level USB serial port, the modbus_receive() function always returns -1.

  • Enable the debug mode, libmodbus provides a function to display the content
    of the Modbus messages and it's very convenient to analyze issues
    (http://libmodbus.org/docs/modbus_set_debug/).

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

  • .\RemoteGPIOControl.exe COM37 COM70 2>out_1.txt
  •   + CategoryInfo          : NotSpecified: (ERROR timed out: select:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

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
Copy link
Author

ZhiyuanYuanNJ commented Jul 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant