Products for USB Sensing and Control
It is currently Sun May 19, 2013 5:59 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Tue Apr 03, 2012 10:19 am 
Offline
Phidgetly

Joined: Wed Mar 14, 2012 4:57 pm
Posts: 19
I am tring to comine the manager sample with the interface sample kit. The problem I am running into is the manager sample does not implement the CPhidgetInterfaceKitHandle IFK.

If I try to create and open the connection using the code from the sample kit it states the connection is already open. I belive this is the result of CPhidgetManager_getAttachedDevices call in the manager sample.

If this opened the interface kit how do I get the CPhidgetInterfaceKitHandle ? If not how do I open the connection?


Top
 Profile Send private message  
 
PostPosted: Tue Apr 03, 2012 10:58 am 
Offline
Phidgetly

Joined: Wed Mar 14, 2012 4:57 pm
Posts: 19
the call to CPhidgetInterfaceKit_getOutputCount allways returns 0 outputs
an example of the code:

Code:
int display_devices(CPhidgetManagerHandle MAN)
{
   int serialNo, version, numDevices, i;
   const char* ptr;

   CPhidgetManager_getAttachedDevices (MAN, &PhidgetDevices, &numDevices);
   tmpDeviceList = numDevices;

   printf("|-   # -|-              Type              -|- Serial No. -|-  Version -|\n");
   printf("|-------|----------------------------------|--------------|------------|\n");


   for(i = 0; i < numDevices; i++)
   {
      CPhidget_getDeviceType(PhidgetDevices[i], &ptr);
      CPhidget_getSerialNumber(PhidgetDevices[i], &serialNo);
      CPhidget_getDeviceVersion(PhidgetDevices[i], &version);

      printf("|- %3d -|- %30s -|- %10d -|- %8d -|\n", i, ptr, serialNo, version);
      printf("|-------|----------------------------------|--------------|------------|\n");
      SerialNumbers[i] = serialNo;

      int numOutputs=0;
      CPhidgetInterfaceKit_getOutputCount((CPhidgetInterfaceKitHandle)PhidgetDevices[i], &numOutputs);
      printf("numOutputs= %d, i=%d\n", numOutputs, i);
   }

   PhidgetControlers = numDevices;
   return 0;
}


Top
 Profile Send private message  
 
PostPosted: Tue Apr 03, 2012 12:18 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2345
Location: Canada
You can't just use the devices reported by the Manager directly - you need to open them first. You should check the return code of your function calls.

You need to create a new CPhidgetInterfaceKitHandle and then call open on it with the serial number reported by the Manager.

-Patrick


Top
 Profile Send private message  
 
PostPosted: Sat Apr 14, 2012 10:38 pm 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
Patrick,
I have simliar problem. I create, open and wait for open, but nothing returned on call for num-anything. Receive return code 5.
Code snippet below.
Regards,
Alan

CPhidgetHandle phid; //value from PhidgetManager attach event
int ifSerial; //value from PhidgetManager attach event
CPhidgetInterfaceKitHandle PhidgetInterfaceKit;
int numInputs = 0;
int rc = 0;

CPhidgetInterfaceKit_create(&PhidgetInterfaceKit);
CPhidget_open(phid, ifSerial);
CPhidget_waitForAttachment(phid, 200);
rc = CPhidgetInterfaceKit_getInputCount(PhidgetInterfaceKit, &numInputs);

// getInputCount returns rc = 5 and numInputs unchanged


Top
 Profile Send private message  
 
PostPosted: Mon Apr 16, 2012 9:17 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2345
Location: Canada
I would increase the waitForAttachment timeout - 200ms may be too low - also, check the return value from waitForAttachement.

-Patrick


Top
 Profile Send private message  
 
PostPosted: Mon Apr 16, 2012 11:53 pm 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
I have tried setting to 0, 2, 2,000 and 20,000 and 200,000.
rc is alwyas zero.
Doesn't appear to actually wait, but comes back almost immediately, well at least is quicker than the fifth to half second that us humans can noticably perceive. Although, is UP UNTIL the time specified. i.e. if connected sooner, CPhidget_waitForAttachment will return immediately, or do I have that wrong?

...or.... is actually connecting, but something else is going on and CPhidget_waitForAttachment's error handlingcode falls into this return code. i.e. bug in CPhidget_waitForAttachment error handling.

Alan.


Last edited by coconutair on Tue Apr 17, 2012 12:06 am, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Tue Apr 17, 2012 12:04 am 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
If I execute Manager_simple and InterfaceKit_simple, they work fine with regard to reading numInputs or numOutputs. Both with VC++ 2101 Express and RAD Studio C++ (what Embarcadero now calls the acquired Borland C++). Problem I have highlighted occurs when attempting to use the above in conjunction. A typical scenario for developing a solution that will dynamically detect, open and work with, say, an InterfaceKit of any serial number. Examples, assume that developer will write a program for one specific serial number.


Top
 Profile Send private message  
 
PostPosted: Tue Apr 17, 2012 8:49 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2345
Location: Canada
Your 1st port says that rc==5 - that means 'not attached', but now you are saying that it's returning -0 - which means 'ok' - so numInputs should be getting updated.

-Patrick


Top
 Profile Send private message  
 
PostPosted: Tue Apr 17, 2012 7:28 pm 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
rc = 0 for CPhidget_waitForAttachment (you had suggested I check that, and I responded without being specific. Apologies).
rc = 5 for subsequent CPhidgetInterfaceKit_getInputCount.

Regards,
Alan


Top
 Profile Send private message  
 
PostPosted: Wed Apr 18, 2012 9:33 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2345
Location: Canada
You have two different handles - 'phid' and 'PhidgetInterfaceKit' - so, even if you call open on phid - you are trying to get the outputCount on PhidgetInterfaceKit - which has not been opened.

It should be:
Code:
CPhidgetInterfaceKit_create(&PhidgetInterfaceKit);
CPhidget_open((CPhidgetHandle)PhidgetInterfaceKit, ifSerial);
CPhidget_waitForAttachment((CPhidgetHandle)PhidgetInterfaceKit, 200);
rc = CPhidgetInterfaceKit_getInputCount(PhidgetInterfaceKit, &numInputs);
-Patrick


Top
 Profile Send private message  
 
PostPosted: Wed Apr 18, 2012 11:12 pm 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
I had code with incorrect casting. I had been playing with other alternatives. However, I now took Manager-simple project and put code into the display_devices routine in Manager-simple.c (using Visual C++ 2010 Express). Compiles fine and executes, but not getting return code 0 for the waitForAttachment. My additions are in red.

//Display the properties of the attached phidget(s) to the screen. We will be displaying the name, serial number and version of the attached device(s).
int display_devices(CPhidgetManagerHandle MAN)
{
int serialNo, version, numDevices, i, numInputs, rc;
const char* ptr;
CPhidgetHandle *devices;
CPhidget_DeviceClass cls;
CPhidgetInterfaceKitHandle PhidgetInterfaceKit;

CPhidgetManager_getAttachedDevices (MAN, &devices, &numDevices);

printf("|- # -|- Type -|- Serial No. -|- Version -|\n");
printf("|-------|----------------------------------|--------------|------------|\n");


for(i = 0; i < numDevices; i++)
{
CPhidget_getDeviceType(devices[i], &ptr);
CPhidget_getSerialNumber(devices[i], &serialNo);
CPhidget_getDeviceVersion(devices[i], &version);
CPhidget_getDeviceClass(devices[i], &cls);
printf("|- %3d -|- %30s -|- %10d -|- %8d -|\n", i, ptr, serialNo, version);
printf("|-------|----------------------------------|--------------|------------|\n");

if (cls = PHIDCLASS_INTERFACEKIT) {
CPhidgetInterfaceKit_create(&PhidgetInterfaceKit);
CPhidget_open((CPhidgetHandle)PhidgetInterfaceKit, serialNo);
rc = CPhidget_waitForAttachment((CPhidgetHandle)PhidgetInterfaceKit, 2000);
printf("Wait return code: ");
printf("%10d\n",rc);
if (rc == 0) {
rc = CPhidgetInterfaceKit_getInputCount(PhidgetInterfaceKit, &numInputs);
printf("numInputs return code: ");
printf("%10d\n",rc);
}

CPhidgetManager_freeAttachedDevicesArray(devices);

return 0;
}


Last edited by coconutair on Sun Jun 03, 2012 6:18 pm, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Thu Apr 19, 2012 9:06 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2345
Location: Canada
Hi,

This will not work because display_devices is called from within the manager attach and detach handlers.

The thread that handled opening you InterfaceKit is the same as the thread that sends out attach and detach events - since this thread is busy in an attach event, your interfacekit will never become attached, no matter how long the waitForAttachment timeout is.

If you want to create/open devices from within manager attach events - this is fine, but you can't use waitForAttachment, you should instead set up an attach event for the new interfacekit - this will get run after the manager attach event returns.

Alternatively, you could stop using manager attach/detach events and just call display_devices from a loop in you main thread (with a short sleep between calls).

-Patrick


Top
 Profile Send private message  
 
PostPosted: Thu Apr 19, 2012 10:02 am 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
Thanks. That was helpful.
Would be useful to have C++ example that detects a phidget from the manager attach event and subsequently works with the attached phidget. I have this working in VB using the secondary attach solution you described (i.e. separate threads). Was recently looking at porting to C++ using example code (which are very useful), and putting prototype together. When I get a C++ prototype working I can send you a Detect-and-Use-simple (Microsoft and Borland).

Regards,
Alan Dyer


Top
 Profile Send private message  
 
PostPosted: Tue May 01, 2012 11:57 am 
Offline
Phidgetsian

Joined: Thu Oct 05, 2006 1:28 pm
Posts: 11
Location: Leander, TX
Had gotten this working. Did not get around to replying for a while.
Thanks for the great support.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group