USBLib_FindDeviceRef (SWI &56340)
Prev | 3.3. Reference management SWIs | Next

## Name

USBLib_FindDeviceRef (SWI &56340) — Obtains a device reference

## On Entry

R0 | device number
R1 | controller reference

## On Exit

R0 | device reference

## Use

This call is used to obtain a device reference from a device number and controller reference.

### Note

The device reference will have its registration count incremented which will require freeing with USBLib_ReferenceDeregister (SWI &56340) when the reference is no longer required.

Example 3.1. Using USBLib_FindDeviceRef

An example of this calls use, the dev is from a "new device" message obtained either by using the USBLib_DevMgrFindFree (SWI &56340) call or from a registered message handler.

    REM find host controller reference
    SYS "USBLib_FindObject",0,controller_name$,USB_REFERENCE_CONTROLLER%,0 TO hc_ref%

    REM find device reference
    SYS "USBLib_FindDeviceRef",device_number,hc_ref% TO dev_ref%

    REM we don't need the controller reference, so deregister it
    SYS "USBLib_ReferenceDeregister", hc_ref%, USB_REFERENCE_CONTROLLER%

    REM do stuff using the reference

    REM we don't need the device reference, so deregister it
    SYS "USBLib_ReferenceDeregister", dev_ref%, USB_REFERENCE_DEVICE%

## Related SWIs

USBLib_GetDefaultPipe (SWI &56340)

USBLib_FindDevice (SWI &56340)

## Related Information

usb_find_device_ref

Prev | Up | Next
Chapter 3. Library SWI Calls | Home | USBLib_FindDevice (SWI &56340)