Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with a serial port in Rust?

I need to perform a simple exchange via serial port in my program. I cannot find any working examples or documentation related to serial ports. I need to open a serial port, configure a port (set speed, parity, stopbits, etc), write/read binary data and then close is.

I tried to use https://github.com/japaric/serial.rs, but this library is outdated (it doesn't even compile on Rust 1.0). Even then, this library only provided functionally on how to configure the serial port but not to use it.

like image 394
fmvin Avatar asked Dec 20 '22 11:12

fmvin


1 Answers

On UNIX serial port is represented by a character device, whcih can be accessed via ordinary system calls that are used for file I/O. The only addition that you would care about with respect to serial port is ioctl, that's what you will use to set baud rate and other parameters.

like image 57
errordeveloper Avatar answered Dec 26 '22 02:12

errordeveloper