USB Libraries Help > USB Device Libraries > USB Device Layer Library > Library Interface > b) Client Core Functions > USB_DEVICE_Close Function
MPLAB Harmony USB Stack
USB_DEVICE_Close Function

This function closes an opened handle to an instance of the USB device layer, invalidating the handle.

C
void USB_DEVICE_Close(
    USB_DEVICE_HANDLE usbDeviceHandle
);
Preconditions

The USB_DEVICE_Initialize function must have been called for the specified device layer instance. USB_DEVICE_Open must have been called to obtain a valid opened device handle.

Parameters
Parameters 
Description 
handle 
A valid open-instance handle, returned from USB_DEVICE_Open 
Returns

None

Remarks

After calling this routine, the handle passed in "usbDevHandle" must not be used with any of the remaining driver routines. A new handle must be obtained by calling USB_DEVICE_Open() before the client may use the device layer again.

Example
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 );

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

//.................
//.................
// User's code
//.................
//.................
// Close handle
USB_DEVICE_Close( usbDevHandle );