I'm trying to work with a LIDAR device that starts streaming data frames 100 times per second from the moment it powers on. There don't seem to be any commands to make it selectively start and stop. I can use a program like cu or my own code to watch the stream, and it works fine most of the time.
But sometimes if I stop the program reading from the serial device and start it again, it'll be able to open the serial device, but it won't receive any data. If I stop the program and start it again, it usually starts working again.
My first guess is that if my timing is bad and there's a data frame coming in while I start the program, that messes up the state of the kernel driver or UART. My second guess is that data received by the serial port while no user program is reading can overflow a buffer or otherwise mess up the state of the UART or kernel buffer, but somehow opening and closing the device fixes the problem.
I've tried using tcflush to clear the input buffer, but that doesn't help.
I could probably deal with this by opening the device, making sure I get data within some timeout, and closing and reopening if it doesn't work the first time. But that's just a bandaid. Anyone know a better solution?
Thanks.
For completeness, I'm using a USB-to-serial adaptor with a Prolific chip, and it's connected to a Jetson Orin Nano, running Ubuntu 20.04.6.