Jump to main content

##

# 2.2.4.15 USB_DEVICE_StateGet Function

## C

    USB_DEVICE_STATE USB_DEVICE_StateGet(
        USB_DEVICE_HANDLE usbDeviceHandle
    );

## Summary

This function returns the current state of the USB device, as described in Chapter 9 of the USB 2.0 Specification.

## Precondition

The USB device layer must have been initialized and opened before calling this function.

## Parameters

Parameters | Description
usbDeviceHandle | Pointer to the device layer handle that is returned from USB_DEVICE_Open

## Returns

USB_DEVICE_STATE_DETACHED - Device is not in any of the known states.

USB_DEVICE_STATE_ATTACHED - Device is attached to the USB, but is not powered.

USB_DEVICE_STATE_POWERED - Device is attached to the USB and powered, but has not been reset.

USB_DEVICE_STATE_DEFAULT - Device is attached to the USB and powered and has been reset, but has not been assigned a unique address.

USB_DEVICE_STATE_ADDRESS - Device is attached to the USB, powered, has been reset, and a unique device address has been assigned.

USB_DEVICE_STATE_CONFIGURED - Device is attached to the USB, powered, has been reset, has a unique address, is configured, and is not suspended.

## Example

    USB_DEVICE_STATE usbDevState;

    // Get USB Device State.
    usbDevState = USB_DEVICE_StateGet( usbDeviceHandle );

    switch(usbDevState)
    {
        case USB_DEVICE_STATE_ATTACHED:
            // Add code here
            break;

        case USB_DEVICE_STATE_POWERED:
           // Add code here
           break;

        default:
            break;
     }

## Remarks

None.