Detect hub connected to USB

Supporting Visual Studio on Windows
Post Reply
carnaby
Phidgetsian
Posts: 13
Joined: Fri Feb 21, 2020 10:35 pm
Contact:

Detect hub connected to USB

Post by carnaby »

I'm trying to detect connection and disconnection of a VINT Hub from the USB port in C# and cannot figure out how to do it from the available documentation. Anyone know how to do this? I can open a phidget voltage ratio input and then disconnect and reconnect the USB cable and the attached and detached events for the individual sensors fire and work, but how to detect initially that the HUB is not connected and subsequently when I plug it in?
fraser
Engineering
Posts: 138
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: Detect hub connected to USB

Post by fraser »

The best way to monitor the state of devices being attached/detached is through the Manager object. There are examples of how to use it available. If you want something specifically for the Hub object alone, you can create a Phidget22.Hub object with attach/detach handlers similar to the other sensors you've worked with
carnaby
Phidgetsian
Posts: 13
Joined: Fri Feb 21, 2020 10:35 pm
Contact:

Re: Detect hub connected to USB

Post by carnaby »

Starting to make sense but I'm not able to get my code working exactly. Can you point me to the examples? I'm having a hard time finding a C# example that opens the manager or a hub and uses their attach/detach events.
carnaby
Phidgetsian
Posts: 13
Joined: Fri Feb 21, 2020 10:35 pm
Contact:

Re: Detect hub connected to USB

Post by carnaby »

I think I have this figured out. I read more documentation and it's making sense. Especially these points:

Be sure to register Attach and Detach event handlers for the Manager before opening it, to ensure you program doesn't miss the events reported for devices already connected to your system.

A Phidget is attached after it has been opened and the Phidget library finds and connects to the corresponding hardware device.
Most API calls are only valid on attached Phidgets.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests