0

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.

Timothy Miller
  • 1,527
  • 4
  • 28
  • 48
  • 1
    Beware your ambiguous use of "*data frame*". A UART frames each byte of data; the UART has no concept of a message or packet or datagram. – sawdust Aug 04 '23 at 02:48
  • With an actual UART such a problem doesn't occur because typically the UART receiver is simply disabled when the serial terminal is closed. Hence all arriving data is simply ignored by the UART, and no data is ever received/read nor processed. When the serial terminal is opened, then the UART receiver is turned back on. If the data is arriving continuously, i.e. no idle time between frames, then the UART may have an issue with proper detection of frames (until the line goes idle). But you're using USB in between the processor and the "UART". Presumably the same conditions apply? – sawdust Aug 04 '23 at 07:56

0 Answers0