Page 1 of 1

getAttachedDevices in Phidget22

Posted: Thu Jul 06, 2017 9:09 am
by atthe
Hello,

this is not really Python question but rather Phidget22 API, but I use python for coding so question is here. I used to get list of Phidgets devices with Manager's getAttachedDevices() function and can't see how to do that now with new API. Please advice correct way.

Thank you.

Re: getAttachedDevices in Phidget22

Posted: Thu Jul 06, 2017 10:55 am
by atthe
Tried to find all attached devices using OnAttached event, but this code is crashed:

Code: Select all

import time
from Phidget22.Devices.Manager import Manager
from Phidget22.Phidget import Phidget

manager = Manager()

def attached(manager, sensor):
    print "something attached: %s at channel: %s" % (str(manager), str(sensor))
    print sensor.getDeviceSerialNumber()

def detached(manager, channel):
    print "something detached: %s at channel: %s" % (str(manager), str(channel))

manager.setOnAttachHandler(attached)
manager.setOnDetachHandler(detached)
manager.open()

while True:
    time.sleep(0.1)
With output:
something attached: <Phidget22.Devices.Manager.Manager instance at 0x7f85597cdfc8> at channel: <Phidget22.Phidget.Phidget instance at 0x7f85583de200>
Segmentation fault
Seems like second parameter passed to OnAttached handler not really correct. When I comment out "print sensor.getDeviceSerialNumber()" I see 20 strings printed at address of second object is the same for all records:
something attached: <Phidget22.Devices.Manager.Manager instance at 0x7f37a8262050> at channel: <Phidget22.Phidget.Phidget instance at 0x7f37a8262248>
something attached: <Phidget22.Devices.Manager.Manager instance at 0x7f37a8262050> at channel: <Phidget22.Phidget.Phidget instance at 0x7f37a8262248>
something attached: <Phidget22.Devices.Manager.Manager instance at 0x7f37a8262050> at channel: <Phidget22.Phidget.Phidget instance at 0x7f37a8262248>
something attached: <Phidget22.Devices.Manager.Manager instance at 0x7f37a8262050> at channel: <Phidget22.Phidget.Phidget instance at 0x7f37a8262248>
How then can I found out what was attached?

Re: getAttachedDevices in Phidget22

Posted: Thu Jul 06, 2017 3:12 pm
by atthe
ok, found that 'Segmentation Fault' is absent on older Debian platform and present only on Ubuntu 16.04 - probably my fault with compilation (not sure how I was able to miss something with ./configure; make). And listening of all 'attached' events after starting of Manager seems can provide all information about present devices.