Detecting sensors attached to VINT hub

Supporting 2.7 and 3.2+
Post Reply
sinman
Fresh meat
Posts: 2
Joined: Wed Sep 27, 2023 5:38 pm
Contact:

Detecting sensors attached to VINT hub

Post by sinman »

How can we detect the port and type of sensor and attached to a VINT hub?

We have a TON of devices with sensors attached to VINT hubs. And we have to manually write down which sensor is attached to which port on the hub to do the configuration.

What I want to do is connect to the vint hub, and have it tell me "port 1 is SND_1000, port 2 is PHIDID_1040, port 3 is PHIDID_1008"

edit: Right now it's only telling me it's a "Voltage Ratio" or "digital output", but not the actual device that's plugged in (there's a TON of "voltage ratio" sensors)
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Detecting sensors attached to VINT hub

Post by Patrick »

Are you using analog sensors or VINT devices? You can use the Phidget manager to enumerate all channels, and get device properties per channel. A VINT Hub will list all of the hubs port modes as well as any attached VINT devices. If you use analog sensors, there isn't any way to read out the sensor type.

-Patrick
sinman
Fresh meat
Posts: 2
Joined: Wed Sep 27, 2023 5:38 pm
Contact:

Re: Detecting sensors attached to VINT hub

Post by sinman »

ok, I think I found it. there was a lot of duplicates in the attach_handler, so I missed that the getDeviceID() would actually get the real deviceID of the attached sensor, and not just the vint hub.

For anyone else coming across this problem, here's the code that discovers everything attached and removes duplicates.

Code: Select all

import json
import time

from beryl_libs.Phidget22.Devices.Manager import Manager
from beryl_libs.Phidget22.DeviceClass import *

sensors = []

def AttachHandler(self, channel):
    sensor = {}
    sensor["DeviceSerialNumber"] = channel.getDeviceSerialNumber()
    sensor["DeviceID"] = hex(channel.getDeviceID())

    json_str = json.dumps(sensor, ensure_ascii=True)

    match = any(json.dumps(s, ensure_ascii=True) == json_str for s in sensors)
    if match == False:
        sensors.append(sensor)


manager = Manager()

manager.setOnAttachHandler(AttachHandler)
manager.open()

time.sleep(5)

manager.close()

print(json.dumps(sensors))
the "DeviceID" in the result corresponds to the Phidget22.DeviceID table (https://www.phidgets.com/?prodid=972#Tab_API, from the Phidget API)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests