Set a Custom Baudrate
thekief opened this issue · 1 comments
I implemented a small application to interact with a serial port that controls some stuff. While the involved USB-to-UART converter (CH340N) officially seems to support only the common baud rates, the original driver for this device used a baud rate of 10000
. For whatever reason that seems the only baud rate to be reliably working.
While working on my application I noticed that the serialport library seems to default to a baud rate of 9600
, atleast that is what port.baud_rate().unwrap()
returns. I dumped the systemcalls of a reliably working Python script and my application and noticed following call missing from my application:
ioctl(3, TCGETS, {c_iflag=IGNPAR, ... ) = 0
ioctl(3, TCGETS2, ..., c_ispeed=10000, c_ospeed=10000}) = 0
ioctl(3, TCSETS2, ... , c_ispeed=10000, c_ospeed=10000}) = 0
Neither setting the baud rate with serialport::new
nor setting the value before opening it with baud_rate
seems to change anything. Any suggestions how I could get that custom baud ate properly running?
Here is some good reference C code that can do this:
https://github.com/Robokishan/custom-baud
I need serialport-rs to support setting arbitrary baud rates.
This is the current state of things attempting to force serialport-rs to use 14400 by calling open_native()
:
Available serial ports: /dev/ttyS0 /dev/ttyUSB0 /dev/ttyS1
Using: /dev/ttyUSB0
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serialport-4.3.0/src/posix/tty.rs:558:18:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
panicing using unreachable!()
is silly.