I wrote an application that should use serial ports on Linux, especially ttyUSB. The read and write operations are performed with the standard select () / read () and write () loops, and there is probably nothing wrong with them, but the initialization code (or the absence of any part) damages something in the tty subsystem. Here he is:
vuxboot(string filename, unsigned baud = B115200) : _debug(false) { _fd = open(filename.c_str(), O_RDWR | O_NOCTTY); if(_fd < 0) throw new io_error("cannot open port");
Another tcsetattr(_fd, TCSANOW, &_termios) is in the destructor, but that doesn't matter.
With or without termios initialization, strange things happen in the system after the application exits. Sometimes a regular cat (or hd ) immediately prints nothing or the same material every time, sometimes it waits and does not display any data that is necessarily sent to the port; and close() ( read() too, but not every time) emits a weird WARNING in dmesg referencing usb-serial.c .
I checked the hardware and firmware dozens of times (even on different machines), and I'm sure it works as intended; Also, I uninstalled the firmware just to print the same message again and again.
How can I use a serial port without destroying anything? Thanks.
c linux tty serial-port
whitequark
source share