CPhidget_getDeviceClass fails when device is not attached

C, C++, and Visual C++
RickDeWater
Fresh meat
Posts: 3
Joined: Mon Mar 17, 2014 7:48 am
Contact:

CPhidget_getDeviceClass fails when device is not attached

Postby RickDeWater » Tue Mar 18, 2014 7:22 am

As the title says, the function CPhidget_getDeviceClass returns an error when there is no device attached.
I find this behavior odd, since each handle is created using a custom function for each type of phidget.
So the created handle should know what the DeviceClass is, even when there is no device attached.

Am I using the functions wrong, or is it supposed to work like this?
And if it is intended, is there a way for me to work around it?

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

Re: CPhidget_getDeviceClass fails when device is not attache

Postby frodegill » Tue Mar 18, 2014 8:10 am

RickDeWater wrote:As the title says, the function CPhidget_getDeviceClass returns an error when there is no device attached.

According to spec:
Parameters:
phid An attached phidget handle.
deviceClass The device class constant.

the created handle should know what the DeviceClass is, even when there is no device attached.
Am I using the functions wrong, or is it supposed to work like this?
And if it is intended, is there a way for me to work around it?

Not sure what you are trying to do, but you MIGHT have a look at Phid_Device_Def in cphidgetconstants.c and see if that may help you.

RickDeWater
Fresh meat
Posts: 3
Joined: Mon Mar 17, 2014 7:48 am
Contact:

Re: CPhidget_getDeviceClass fails when device is not attache

Postby RickDeWater » Tue Mar 18, 2014 8:28 am

I want to get the device class of a generic CPhidgetHandle that is not necessarily attached.
I suppose this is not possible, since the function requires it to be attached (even though the library should have all the information it needs to return a proper value).
I guess I'll add a virtual function in my phidget class for now, that I override manually for each derived type, though it is not a pretty solution.

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

Re: CPhidget_getDeviceClass fails when device is not attache

Postby Patrick » Tue Mar 18, 2014 9:50 am

It's true that this information is in the structure, so there's really no reason why the handle need to be attached. I will change it in the library and do a release. If you are writing code for general release, then you will still need to handle the old behaviour for people who don't have the newer release.

Another way to find the device class would be to read it directly from the device structure. This structure is defined in cphidget.h - you can get it from the linux source release. Then you would just need to add it to your code somewhere and you could do:

Code: Select all

CPhidgetInterfaceKitHandle device;
CPhidgetInterfaceKist_create(&device);
int deviceClass = ((struct _CPhidget *)device)->deviceID;

-Patrick


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 3 guests