Multiple Phidgets in a VB.NET project

Supporting Visual Studio on Windows
dschex
Fresh meat
Posts: 2
Joined: Fri Jun 28, 2013 9:17 am
Contact:

Multiple Phidgets in a VB.NET project

Postby dschex » Fri Jun 28, 2013 9:29 am

Hello,

This seems to be a recurring question that has not been answered.

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?

Thanks,


Dave.

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: Multiple Phidgets in a VB.NET project

Postby frodegill » Fri Jun 28, 2013 10:01 am

dschex wrote: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?

I do this right now, but in C++/C and in code not quite ready for sharing. If you want, I can post some pseudo-code of how I do it in C++/C.

dschex
Fresh meat
Posts: 2
Joined: Fri Jun 28, 2013 9:17 am
Contact:

Re: Multiple Phidgets in a VB.NET project

Postby dschex » Fri Jun 28, 2013 10:54 am

Frodegill,

Beggars cannot be choosers--please post whatever your are willing to post!

Thanks for the quick response.


Dave.

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: Multiple Phidgets in a VB.NET project

Postby frodegill » Fri Jun 28, 2013 2:28 pm

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_create
CPhidgetManager_set_OnAttach_Handler
CPhidgetManager_open
CPhidgetManager_getAttachedDevices
foreach attached device, call the manager OnAttach_Handler (passing the device handler, as if it was being attached now)
CPhidgetManager_freeAttachedDevicesArray
wait until shutdown requested
CPhidgetManager_close
CPhidgetManager_delete


The manager OnAttach_Handler:
CPhidget_getDeviceClass
based on the DeviceClass:
CPhidget<DeviceClass>_create
CPhidget_set_OnAttach_Handler
CPhidget_set_OnDetach_Handler
and any other callback handlers you need
CPhidget_getSerialNumber
CPhidget_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_close
CPhidget_delete


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 2 guests