How do I manage multiple Phidget devices in a VB.NET (or C#) program without having to record serial numbers in advance?

I would like to get a list of attached serial numbers, query some of the digital inputs on each device (as I will use a portion of the inputs to identify the purpose of the device) and then attach by them by serial number.

This alleviates the user from having to read and enter the serial number in the software and allows a user to replace a board by only duplicating it's "wired up" configuration.

All the examples of multiple devices use a hard-coded serial number.

On one hand, I can get a list of devices by serial number (using the manager), or I can attach multiple devices if the software "knows" the serial number, but I don't see any examples where the devices can be queried and then attached appropriately per software.

Has anybody done this? Can you please share your code or point me to examples that accomplish this?

Here is pseudo-code of how I do it. I don't say this is the best/perfect/only way of doing it, I just say it works for me

The manager:

CPhidgetManager_createCPhidgetManager_set_OnAttach_HandlerCPhidgetManager_openCPhidgetManager_getAttachedDevicesforeach attached device, call the manager OnAttach_Handler (passing the device handler, as if it was being attached now)CPhidgetManager_freeAttachedDevicesArraywait until shutdown requestedCPhidgetManager_closeCPhidgetManager_delete

The manager OnAttach_Handler:

CPhidget_getDeviceClassbased on the DeviceClass:CPhidget<DeviceClass>_createCPhidget_set_OnAttach_HandlerCPhidget_set_OnDetach_Handlerand any other callback handlers you needCPhidget_getSerialNumberCPhidget_open(using handle and serial)

The phidget OnAttach_Handler:

Do whatever you want, the phidget is alive!

The phidget OnDetach_Handler:

Stop doing whatever you want, the phidget isn't here anymore..Whenever it is safe (as in, no longer in the callstack):CPhidget_closeCPhidget_delete