Hello,
We have a device that communicates through the USB port “\$device\com0” with an external application.
The app sends and receives packets that let it control the device to perform activities, but customers notified me that sometimes the device does not reply, not immediately.
I have been able to replicate this bug by sending the same packet they used and also when I tried with several variations of it: when the device should receive a packet of exactly 512 bytes, the breakpoints I set in debug for the code that manages to read from the USB port don’t break, or they show the ReadFile call exited with 0 bytes read.
if I change anything in the packet to vary its overall length to either less or more than 512 bytes, suddenly the device receives all the previous “unread” packets plus the latest new one.
Another way I can force it to read these packets is to send at least 8 of them, leading to the device suddenly reading a total amount of 4096bytes.
Without having to reveal too much of our proprietary packet protocol, I can tell you that the first bytes of the packet are very similar in each one:
- 0x4B (fixed)
- 0x42 (fixed for this scenario)
- 0x01 (varies when changing the length of the packet, but fixed for this scenario)
- 0xFA (varies when changing the length of the packet)
- 0x7B ‘{’ (start bracket for the JSON string payload inside the packet)
- 0x22 ‘"’ (double quote preceding the first json property)
- …
Can you help me understand how this is possible?
I’m quite sure this issue is not on the external application on the other side, since our customers have this issue on their android app, while I can replicate it using a windows desktop software.
A quick search on google did not reveal any specific byte sequence that I should know of that could make the USB port behave like this (the active sync is disabled by default on our devices, except the one I use, but it is disabled on my PC by the driver we use for our desktop application).
The USB COM0 port is set up as default by T20, except for the Baud Rate, which we changed to 921600 for this project (but this issue is present also with the default settings). Here is the list, just for completeness:
property | value |
---|---|
BaudRate | 921600 |
fBinary | 1 |
fParity | 0 |
fOutxCtsFlow | 0 |
fOutxDsrFlow | 0 |
fDtrControl | DTR_CONTROL_ENABLE |
fDsrSensitivity | 0 |
fTXContinueOnXoff | 0 |
fOutX | 0 |
fInX | 0 |
fErrorChar | 0 |
fNull | 0 |
fRtsControl | RTS_CONTROL_ENABLE |
fAbortOnError | 0 |
fDummy2 | 0 |
wReserved | 0 |
XonLim | 16384 |
XoffLim | 4096 |
ByteSize | 8 |
Parity | 0 |
StopBits | 0 |
XonChar | 17 |
XoffChar | 19 |
ErrorChar | 13 |
EofChar | 13 |
EvtChar | 13 |
wReserved1 | 0 |
Does this have anything to do with the DTR and RTS settings being enabled in these configurations? I’m not knowledgeable on this topic yet.
Please help.
Thank you
Colibri T20 256MB 1.2B
Custom board
WEC7 BSP 2.4