RxUsbRegisterChangeNotification
From EDM2
Contents
Description
Registers semaphores for generic attach/detach notification of USB devices.
Syntax
rc = RxUsbRegisterChangeNotification(NotifyID,hDevAdd,hDevRem)
Parameters
- NotifyID
- the name of the variable to receive the Notification Identifier.
- hDevAdd
- the handle of the event semaphore to be posted on device attach.
- hDevRem
- the handle of the event semaphore to be posted on device detach.
Return Code
0x0000 - NO_ERROR
Errors
0x0006 - ERROR_INVALID_HANDLE 0x0057 - ERROR_INVALID_PARAMETER 0x005F - ERROR_INTERRUPT 0x0067 - ERROR_TOO_MANY_SEM_REQUESTS 0x0069 - ERROR_SEM_OWNER_DIED 0x1B58 - USB_NOT_INIT 0x1B59 - USB_ERROR_NO_MORE_NOTIFICATTIONS 0xFF06 - ERROR_INVALID_HANDLE 0xFF1F - ERROR_GEN_FAILURE 0xFF57 - ERROR_INVALID_PARAMETER 0xFF64 - ERROR_TOO_MANY_SEMAPHORES
Remarks
Device attach/detach notifications may be obtained by registering event semaphores to be posted upon attach/detach of USB devices. The RexxUtil library provides functions to work with event semaphores. Some of these are used in the example code.
Example Code
/* add SysCreateEventSem */ rc = RxFuncAdd('SysCreateEventSem','RexxUtil','SysCreateEventSem') say '+SysCreateEventSem(),RC=0x'd2x(rc) /* invoke SysCreateEventSem() */ hSemAttach = SysCreateEventSem() say '*SysCreateEventSem(),RC=0x'd2x(rc) hSemDetach = SysCreateEventSem() say '*SysCreateEventSem(),RC=0x'd2x(rc) /* drop SysCreateEventSem */ rc = RxFuncDrop('SysCreateEventSem') say '-SysCreateEventSem(),RC=0x'd2x(rc) /* add RxUsbRegisterChangeNotification */ rc = RxFuncAdd('RxUsbRegisterChangeNotification','usbcalls','RxUsbRegisterChangeNotification') say '+RxUsbRegisterChangeNotification(),RC=0x'd2x(rc) /* invoke RxUsbRegisterChangeNotification */ hDevAdd = hSemAttach; /* attach semaphore handle */ hDevRem = hSemDetach; /* detach semaphore handle */ drop NotifyID /* to receive the notification identifier */ rc = RxUsbRegisterChangeNotification(NotifyID,hDevAdd,hDevRem) say '*RxUsbRegisterChangeNotification(),RC=0x'd2x(rc) /* drop RxUsbRegisterChangeNotification */ rc = RxFuncDrop('RxUsbRegisterChangeNotification') say '-RxUsbRegisterChangeNotification(),RC=0x'd2x(rc) /* add SysWaitEventSem */ rc = RxFuncAdd('SysWaitEventSem','RexxUtil','SysWaitEventSem') say '+SysWaitEventSem(),RC=0x'd2x(rc) /* invoke SysWaitEventSem() */ timeout = 8000; /* await 8 seconds */ rc = SysWaitEventSem(hSemAttach,timeout) say '*SysWaitEventSem(),RC=0x'd2x(rc) if (rc=0) then say 'obtained Attach Notification' rc = SysWaitEventSem(hSemDetach,timeout) say '*SysWaitEventSem(),RC=0x'd2x(rc) if (rc=0) then say 'obtained Detach Notification' /* drop SysWaitEventSem */ rc = RxFuncDrop('SysWaitEventSem') say '-SysWaitEventSem(),RC=0x'd2x(rc)