I see your code is enqueuing data even when there isn't any (bytes at port = 0). You should move the enqueue into where you are receiving data. And that's the other thing. Even though that is the way the (ugh) LabVIEW example shows you how to do it, using bytes at port to decide how many bytes to read is a dangerous thing because if the amount actually changes in between bytes at port and the serial read, you'll miss some data if it is the last read. Maybe this is what is causing the USB loop to seem to have delays? there's always a better way than this, but how you do it depends on ho the messages arrive.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the
CLAD Nugget.