Check the result after each send, receive or other result-producing command. Most results tell you what to do next: use the data, try later, or wait for the connection.
Most USB commands are called on their own line. After the call, check USB_Result. For example, call USB_Read() first; do not write bResult = USB_Read() or use USB_Read() inside an If condition.
USB_Read()
If USB_Result = USB_OK Then
' Use RXReport and USB_RxLength now.
EndIf
Check the result straight away: another command can replace it. Copy it to your own Byte variable if you need to keep it. These calls leave the result unchanged: USB_Service(), USB_ISR(), USB_DisableIRQ(), USB_GetEvents(), USB_ClearErrors() and USB_Tick().
|
Result |
Value |
What it means |
|
USB_OK |
0 |
This operation succeeded at the stage described for that command. |
|
USB_BUSY |
1 |
A required buffer or operation is busy; try later. |
|
USB_OFFLINE |
2 |
Unconfigured or suspended; CDC can also require DTR before data transfer. |
|
USB_BAD_LENGTH |
3 |
Invalid length or index/count; initialization on Positron16 can also report invalid USB RAM placement. |
|
USB_HALTED |
4 |
The host halted the endpoint; the host must clear that halt. |
|
USB_NO_DATA |
5 |
Nothing is waiting to be read. This is normal between messages. |
|
USB_NOT_SUPPORTED |
6 |
The mode does not support the operation, or its prerequisites are absent. |
|
USB_TIMEOUT |
7 |
A bounded wait ended before the operation became ready. |
Busy or no data is often normal. Retry a busy operation later. A halted data endpoint (USB data channel) must be cleared by the computer; do not change the hardware buffer flags yourself.
|
Alias |
Equivalent |
Meaning |
|
mUSBService() |
USB_Service() |
Common servicing. |
|
HID_WriteReport() |
One nonblocking full HID report; check USB_Result. |
|
|
HID_ReadReport() |
USB_Read() |
Receive through the common read procedure. |
|
tUSB_Attached |
Configuration state, not a physical cable detector. |
Use the USB_... names when writing new examples so their behavior matches the reference above.
Created with the Personal Edition of HelpNDoc: Effortlessly upgrade your WinHelp HLP help files to CHM with HelpNDoc