Jump to main content

##

# 2.2.4.5 USB_DEVICE_Open Function

## C

    USB_DEVICE_HANDLE USB_DEVICE_Open(
        const SYS_MODULE_INDEX instanceIndex,
        const DRV_IO_INTENT intent
    );

## Summary

This function opens the USB device layer instance specified by instance index and returns a handle. This handle must be provided to all other client operations to identify the caller and the instance of the USB device layer. An instance of the Device Layer can be opened only once. Trying to open the Device Layer more than once will return a invalid device layer handle.

## Precondition

This function must be called after USB device driver initialization and after the initialization of USB Device Layer.

## Parameters

Parameters | Description
instanceIndex | USB device layer instance index
intent | This parameter is ignored. The Device Layer will always open in read/write and exclusive mode.
void | None

## Returns

If successful, returns a valid device layer handle. Otherwise, it returns USB_DEVICE_HANDLE_INVALID.

## Example

    // This code example shows how the
    // USB Device Layer can be opened.

    USB_DEVICE_HANDLE usbDeviceHandle;

    // Before opening a handle, USB device must have been initialized
    // by calling USB_DEVICE_Initialize().

    usbDeviceHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0,
                                    DRV_IO_INTENT_READWRITE );

    if(USB_DEVICE_HANDLE_INVALID == usbDeviceHandle)
    {
        //Failed to open handle.
    }

## Remarks

None.