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

Set a Custom Baudrate #156

Open
thekief opened this issue Feb 3, 2024 · 1 comment
Open

Set a Custom Baudrate #156

thekief opened this issue Feb 3, 2024 · 1 comment

Comments

@thekief
Copy link

thekief commented Feb 3, 2024

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?

@mrcbax
Copy link

mrcbax commented Feb 27, 2024

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.

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

2 participants