stephane / libmodbus

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

RTU baud rate handling is broken in 3.1.9 in Linux #673

Closed jcarrano closed 1 year ago

jcarrano commented 1 year ago

libmodbus version

3.1.9

OS and/or distribution

Linux

Environment

x86_64, but the issue should affect all other archs too

Description

_modbus_rtu_connect() used to have a big switch-case to convert numeric baud rates to the symbolic constants from termios.h used for speed_t in cfgetispeed/cfgetospeed (B1200, B2400, etc.).

Commit fa2079859d82965c5be417cc3985df141d720e0a removed this code with a message Remove constraints on baud rate values, but it was not a "constraint", it was a necessary conversion. cfgetispeed/cfgetospeed can only accept the BXXXX symbolic constants, and the code as shown in the documentation is now invalid.

Actual behavior if applicable

Opening a RTU context fails with "22 Invalid Argument".

Expected behavior or suggestion

The code should work as before, converting the numbers into constant.

With the current code, passing the BXXXX constants to modbus_new_rtu would probably work, but that would be changing the API and also it is non-portable.

jcarrano commented 1 year ago

seems fixed in 3.1.10