USB protocol error checking
Posted: Thu Oct 03, 2019 5:07 am
Hi Tom,
We occasionally encounter bad USB cables, which can cause random weirdness. Of course, the ideal is to have perfect connections, but it is hard to achieve in practice: we find cables with 10 ohm impedance in the shield connection, USB connectors that don't reliably contact the shield, and so on.
How can we make this rock-solid?
The problem we are encountering is that when there is a bad connection, there is no checksum in the pc->kflop protocol, so nonsensical data gets through to the software. This is very hard to deal with, since users think it is bugs in our software and the tech support becomes a nightmare. What we would like to do is reliably recognize when there are errors in the USB link, so that we can gracefully shut down the software and notify the user.
We are using Linux and have our own KMotionServer, but it is based on the Windows code. Maybe the FTDI library for Linux just sucks, but you may have some suggestions (being more familiar with the FTDI chip).
It would be most useful if we could somehow validate the main status message, since that is critical to our software function. This comes from the kflop as a big bunch of hex which we parse into numbers. If it gets truncated we can reject that message since the length is checked, but we are at its mercy if it decides to flip a few bits here and there. It really would be better if the FTDI library returned an error code, but it doesn't do that, and just seems to keep going (in a fashion) after mangling the data. I always thought USB would have some sort of checksum, but evidently it doesn't.
My impression is that the comms are really fragile. With Ethernet if you get a packet you know it's good, so it degrades gracefully with noise. But serial protocol over USB does not have robust error detection. Relying on CRLF at the end of a message gives no redundancy.
At any cost, we wish to detect comms errors reliably, or make the USB link electrically perfect. Our only option at this point seems to be to mount a Raspberry Pi etc. right near the kflop, and use Ethernet to connect the PC and R.Pi. This will make the USB perfect (or nearly so). But it's a PITA to have yet another device to program and fit in the cabinet.
Regards,
SJH
We occasionally encounter bad USB cables, which can cause random weirdness. Of course, the ideal is to have perfect connections, but it is hard to achieve in practice: we find cables with 10 ohm impedance in the shield connection, USB connectors that don't reliably contact the shield, and so on.
How can we make this rock-solid?
The problem we are encountering is that when there is a bad connection, there is no checksum in the pc->kflop protocol, so nonsensical data gets through to the software. This is very hard to deal with, since users think it is bugs in our software and the tech support becomes a nightmare. What we would like to do is reliably recognize when there are errors in the USB link, so that we can gracefully shut down the software and notify the user.
We are using Linux and have our own KMotionServer, but it is based on the Windows code. Maybe the FTDI library for Linux just sucks, but you may have some suggestions (being more familiar with the FTDI chip).
It would be most useful if we could somehow validate the main status message, since that is critical to our software function. This comes from the kflop as a big bunch of hex which we parse into numbers. If it gets truncated we can reject that message since the length is checked, but we are at its mercy if it decides to flip a few bits here and there. It really would be better if the FTDI library returned an error code, but it doesn't do that, and just seems to keep going (in a fashion) after mangling the data. I always thought USB would have some sort of checksum, but evidently it doesn't.
My impression is that the comms are really fragile. With Ethernet if you get a packet you know it's good, so it degrades gracefully with noise. But serial protocol over USB does not have robust error detection. Relying on CRLF at the end of a message gives no redundancy.
At any cost, we wish to detect comms errors reliably, or make the USB link electrically perfect. Our only option at this point seems to be to mount a Raspberry Pi etc. right near the kflop, and use Ethernet to connect the PC and R.Pi. This will make the USB perfect (or nearly so). But it's a PITA to have yet another device to program and fit in the cabinet.
Regards,
SJH