Yes, you can connect any number of Phidgets to the same computer (until you run out of USB ports- then you need a USB hub).
You can simply open the objects on your HUB0000 and 1002_0B in the same program. For example, if you had three DST1002 sensors connected to the HUB0000, and you wanted to use one LED on VINT port 3 and two channels of the 1002_0B, you could open them all like this in Python:
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.DistanceSensor import *
from Phidget22.Devices.VoltageOutput import *
from Phidget22.Devices.DigitalOutput import *
import time
def onDistanceChange(self, distance):
print("Distance: " + str(distance))
def main():
sensor0 = DistanceSensor()
sensor1 = DistanceSensor()
sensor2 = DistanceSensor()
voltageOut0 = VoltageOutput()
voltageOut1 = VoltageOutput()
led0 = DigitalOutput()
sensor0.setHubPort(0)
sensor1.setHubPort(1)
sensor2.setHubPort(2)
voltageOut0.setChannel(0)
voltageOut1.setChannel(1)
led0.setHubPort(3)
led0.setIsHubPortDevice(True)
sensor0.setOnDistanceChangeHandler(onDistanceChange)
sensor1.setOnDistanceChangeHandler(onDistanceChange)
sensor2.setOnDistanceChangeHandler(onDistanceChange)
sensor0.openWaitForAttachment(5000)
sensor1.openWaitForAttachment(5000)
sensor2.openWaitForAttachment(5000)
voltageOut0.openWaitForAttachment(5000)
voltageOut1.openWaitForAttachment(5000)
led0.openWaitForAttachment(5000)
try:
input("Press Enter to Stop\n")
except (Exception, KeyboardInterrupt):
pass
sensor0.close()
sensor1.close()
sensor2.close()
voltageOut0.close()
voltageOut1.close()
led0.close()
main()
- The first block in the main function declares all of the different channels.
- The second block sets all of the addressing parameters. You can read about all of the possible addressing options
on this page.
- The third block sets the data handler function for the distance sensors. In this example, they all use the same one but you could instead specify different functions for each sensor, or you could use the "self" variable inside the event to determine which distance sensor is sending the event (for more info about this including how to do it in other programming languages, see the "Distinguishing Events" section of
this page).
- The fourth block is where each channel is opened.
- The last part at the end is where each channel is closed.