getPhidgets() returning empty vector

Supporting Java SE version 7 and up
irazinkov
Fresh meat
Posts: 2
Joined: Sun Oct 16, 2011 6:15 pm
Contact:

getPhidgets() returning empty vector

Postby irazinkov » Sun Oct 16, 2011 6:26 pm

Hi,

I modified the PhidgetControlPanel example to include the following lines:

Code: Select all

 manager = new Manager();
           
           
            attach_listener = new ManagerAttachListener(this, this.deviceTbl);
            detach_listener = new ManagerDetachListener(this, this.deviceTbl);
       
            manager.addAttachListener(attach_listener);
            manager.addDetachListener(detach_listener);
           
            manager.open();
**addition**
            Vector phidgets = manager.getPhidgets();
            Boolean list_2=phidgets.isEmpty();
                       
            jTextArea1.insert(list_2.toString(), 0x0);
 **end of addition**           


jTextArea1 is just a text box in the panel. I'm using NetBeans.

The *.isEmpty() method always returns true, however, i can see the model and name of the attached stepper motor controller. See attached image for the exact output.
Attachments
Picture 1.png
Picture 1.png (23.72 KiB) Viewed 4746 times

mphi
Phidgetly
Posts: 39
Joined: Tue Nov 16, 2010 4:27 pm
Contact:

Re: getPhidgets() returning empty vector

Postby mphi » Mon Oct 17, 2011 9:07 am

After calling open, the library needs time to detect for an attached Phidget. The Vector that is returned by getPhidgets() is updated right before the attach event triggers.

To ensure that the library has enough time to detect the Phidgets, you can put getPhidgets() in the attach method.

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

Re: getPhidgets() returning empty vector

Postby Patrick » Mon Oct 17, 2011 9:53 am

Or, you can just put a small sleep - ~200ms after calling open, and it will have had time to fill the list with any attached Phidgets.

-Patrick

irazinkov
Fresh meat
Posts: 2
Joined: Sun Oct 16, 2011 6:15 pm
Contact:

Re: getPhidgets() returning empty vector

Postby irazinkov » Mon Oct 17, 2011 12:14 pm

Hi guys,

thank you, i was thinking exactly along those lines. I guess just wasnt sure of it. Anyway, the Thread.sleep(200); works perfect.

thank you,
ivan

mraiser
Fresh meat
Posts: 3
Joined: Sun Jan 09, 2011 10:13 am
Contact:

Re: getPhidgets() returning empty vector

Postby mraiser » Sat Jun 13, 2015 2:16 pm

I am having a similar issue. If the Phidget is already attached when I start my app, it is not listed in getPhidgets(). If I physically attach the Phidget after launching my app, it shows up in the list. Is there any way to list Phidgets that were already physically attached to the computer prior to launching the app?

Many thanks,
-Marc


Return to “Java”

Who is online

Users browsing this forum: No registered users and 0 guests