UsbStatus

Availability All terminals
Description Legacy: Use UsbIsConnected and UsbIsPowered
Syntax int UsbStatus( void );
Arguments None
Returns
USB_NOT_CONNECTED Not connected to the USB cable
USB_POWERED Connected to the USB cable, but the COM port isn't open
USB_OK Connected to the USB cable and the COM port on the PC or laptop is enumerated (use GetDSR() to detect if the port is open or not)
USB_ERR_NOTREADY Connected to the USB cable, but not ready for communication
USB_ERR_BUSY Connected to the USB cable, the port is open, but currently busy (not an error state)
Remarks This function can be used to check if the device is connected to the USB cable and whether it's possible to successfully communicate with the attached PC or laptop.
Example
#include <stdio.h>
#include "lib.h"

void main( void )
{
    int previous_status, current_status;

    SystemSetting("8Z");    // Disable charge indicator

    previous_status = -1;

    for(;;)
    {
        current_status = UsbStatus();

        if(current_status != previous_status)
        {
            previous_status = current_status;

            switch( current_status )
            {
                case USB_NOT_CONNECTED:
                    GoodReadLed(ORANGE, -1);
                    break;
                case USB_OK:
                    GoodReadLed(GREEN, -1);
                    GoodReadLed(RED, 0);
                    break;
                default:
                    GoodReadLed(RED, -1);
                    GoodReadLed(GREEN, 0);
                    break;
            }
        }
        Idle();
    }
}