Enumerating all channels from PhidgetManager

C, C++, and Visual C++
Post Reply
jcelerier
Fresh meat
Posts: 1
Joined: Mon Feb 12, 2018 8:16 am
Contact:

Enumerating all channels from PhidgetManager

Post by jcelerier »

Hello,
in the Phidget22 API I'm trying to get all the channels (basically, I'd like to recreate the phidget tree UI from my side, ie enumerate all the phidget devices & channels on the system.).

I have the following code:

Code: Select all


  PhidgetManager_create(&m_hdl);
  PhidgetManager_setOnAttachHandler(
      m_hdl,
      [] (PhidgetManagerHandle phidm, void *ptr, PhidgetHandle phid) {
         ...
      },
      this);

  PhidgetManager_setOnDetachHandler(...);

  PhidgetManager_open(m_hdl);
Now, what must I do from the PhidgetHandle to get all the channels and child objects ?
For instance, by calling all the various Phidget_getWhatever on the handles I get from the callback, functions I could get :

Code: Select all

Device Name                | Serial | Status | Device class      | Device ID
---------------------------------------------------------------------------
PhidgetSpatial 3/3/3 Basic | 296969 | 0      | PHIDCLASS_SPATIAL | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969 | 0      | PHIDCLASS_SPATIAL | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969 | 0      | PHIDCLASS_SPATIAL | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969 | 0      | PHIDCLASS_SPATIAL | PHIDID_1042 
In all cases, Phidget_getIsChannel is false, like Phidget_getIsHubPortDevice. I also tried with VINT hubs : I tried with all these devices:

* 6-Port USB VINT Hub Phidget (PHIDCLASS_HUB)
* 4x Digital Input Phidget (PHIDCLASS_VINT)
* Thumbstick Phidget (also PHIDCLASS_VINT, because it's plugged on it ? or all VINT phidgets share this class ?)
* Wheatstone Bridge Phidget (also PHIDCLASS_VINT)

Calling Phidget_getChildDevices on the PhidgetHandle gives me an error 8 (EPHIDGET_FAULT, "Address Issue").

So basically, how can I get from the PhidgetManager-originating PhidgetHandles, the actual Phidget objects, and know their position in the hierarchy of hubs ?

Thanks
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Enumerating all channels from PhidgetManager

Post by Patrick »

Using the manager, every object you get back in the attach handler is a channel handle - getIsChannel should give back true. If you are getting false from getIsChannel, this could mean that you're using the handle outside of the attach handler context. If you want to retain a handle from an attach event for further use, you need to call Phidget_retain() on it before the attach handler exits. You would then need to call Phidget_release() when you're finished with it.

From a Phidget channel handle, you can call getParent to get a device handle. You can keep calling getParent on each parent until you get a NULL to travel up the tree to a root device. For example: VINT device channel -> VINT device -> VINT USB Hub -> NULL. The Phidget control panel builds up a tree of devices in this way as attach events come in, with each new channel either adding a new parent device to the tree, or matching up with an already added device. When you are finished with a device, you should call Phidget_release() to free up the memory.

Phidget_getChildDevices is undocumented. This function accepts device handles, or you can pass in NULL to get a list of root devices, and work your way down the tree from there. Make sure to call Phidget_releaseDevices when you've finished with the array of devices. There currently isn't a way to poll for a list of device channels, these are only available via the attach event.

-Patrick
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Enumerating all channels from PhidgetManager

Post by mparadis »

You need to print out the channelClass and the channel to get the full picture.

For example, your 1042 would look like this:

Code: Select all

Device Name                | Serial  | Channel Class | Channel | Device ID
----------------------------------------------------------------------------
PhidgetSpatial 3/3/3 Basic | 296969  | Accelerometer | 0       | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969  | Magnetometer  | 0       | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969  | Gyroscope     | 0       | PHIDID_1042 
PhidgetSpatial 3/3/3 Basic | 296969  | Spatial       | 0       | PHIDID_1042 
The manager is seeing a channel attach event for each of these four objects, but they appeared to be the same because you were only looking at device-related fields. channel, channelClass, and channelClassName will help differentiate them.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest