Page 1 of 2

Getting Started with Python and Debian

Posted: Mon Feb 26, 2018 7:55 pm
by monteshaffer
Hi,

I am trying to get started. I am trying to figure out how to list "what's attached" from the CLI on Debian.

I have setup my python work environment. I got ./helloWorld to work and I seem to be able to get a typical python3 script to run without errors (exception time out is what I get).

Output from ./helloWorld [gcc compiled]

Code: Select all

./HelloWorld
Opening...
Phidget Simple Playground (plug and unplug managers)
Press Enter to end anytime...
Hello Device 6-Port USB VINT Hub Phidget, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Digital Input Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Digital Output Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Input Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910
Hello Device Hub Port - Voltage Ratio Mode, Serial Number: 496910

I have a VINT hub attached, and to this hub I am trying to plugin a few devices: 1112, HIN1101_0, 1129, 1106, 1131. Certainly, I will do them one at a time, but evetually they will all be there.

When I read a lot of the sample code, it has a certain logic, "I know this is attached, and I proceed" ... I want to do just the opposite "list what is attached"

so I want "lsphidget" similar to "lsusb" on the debian platform. So in this setup a

Code: Select all

python3 lsphidget.py
And for starters, let's just consider the 1112 element is plugged in.

This is a VoltageRatio Input that I plugged into VINT hub port #2, but that is not the point... I want to list that it is attached, where it is attached, and then I can identify and code from there. I want to scan the VINT Hub with "lsphidget".

How?

Re: Getting Started with Python and Debian

Posted: Tue Feb 27, 2018 8:24 am
by mparadis
It sounds like you want the Phidget manager (sometimes called "HelloWorld") example. You can find it in the list of sample code for python. It launches an event for each Phidget channel it can see, so you can easily maintain a list in software or print out whenever a channel becomes available or disappears. In its current form, the manager example only prints out the DeviceName and DeviceSerialNumber of each channel, but you can make it more descriptive by adding properties like ChannelClassName and Channel.

For sensors like the 1112, 1129, 1106, and 1131, it's not actually possible to detect their presence. These are simple sensors that just output 0-5V, with no built-in intelligence, so as far as the VINT hub is concerned, it's just a voltage source. If you know which sensor is connected to a given port, you can set SensorType in order to have it convert to the proper units, if applicable. The only way you might be able to detect if a sensor is connected to a port is by reading the voltage to see if it is a nonzero value (but even then, there's no way to tell which sensor it is).

Re: Getting Started with Python and Debian

Posted: Thu Mar 01, 2018 7:03 am
by monteshaffer
I don't see "PhidgetManager" ported to python.

https://www.phidgets.com/?view=code_samples&lang=Python

Is it the "Manager" python script?

Or is it a service level script compiled like the gcc example used during install?

Or is it the "API" that I have to create my own "PhidgetManager" using these DOCS?

https://www.phidgets.com/?view=api

From what I understand, this page outlines:
https://www.phidgets.com/docs/Phidget_Manager

The "HelloWorld" comment - I don't see a python file called helloworld

... I guess it is called "Manager" which links to Phidget22_HelloWorld_Python_Ex_20180228\HelloWorld.py

Is that correct?

Re: Getting Started with Python and Debian

Posted: Thu Mar 01, 2018 8:46 am
by mparadis
That is correct, the manager example is HelloWorld.py, and should show you how to use the Phidget Manager.

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 6:59 am
by monteshaffer
Ok, so I have taken HelloWorld and morphed it to print more output. I have HIN1101_0 and 1112 plugged in.

Code: Select all

root@ats:/home/mshaffer/phidgets/python/monte# python3 lsphidget.py
lsphidget
service
service
Opening....
Phidget Simple Playground (plug and unplug devices)
Press Enter to end anytime...
Hello to Device 6-Port USB VINT Hub Phidget, Serial Number: 496910
{'channel': {'number': 0, 'class': 13, 'name': 'VINT Hub', 'class-name': 'PhidgetHub'}, 'hub': {'number': <Phidget22.Phidget.Phidget object at 0x7f906fa54b70>, 'port-count': 6, 'port': 0}, 'parent': {'object': <Phidget22.Phidget.Phidget object at 0x7f906fa54be0>}, 'device': {'serial': 496910, 'label': '', 'version': 117, 'name': '6-Port USB VINT Hub Phidget', 'class': 8, 'sku': 'HUB0000', 'id': 64, 'class-name': 'PhidgetHub'}}
Hello to Device Phidget Dial, Serial Number: 496910
{'channel': {'number': 0, 'class': 8, 'name': 'Encoder Input', 'class-name': 'PhidgetEncoder'}, 'hub': {'number': <Phidget22.Phidget.Phidget object at 0x7f906fa54b70>, 'port-count': 6, 'port': 3}, 'parent': {'object': <Phidget22.Phidget.Phidget object at 0x7f906fa54be0>}, 'device': {'serial': 496910, 'label': '', 'version': 101, 'name': 'Phidget Dial', 'class': 21, 'sku': 'HIN1101', 'id': 109, 'class-name': 'PhidgetVINT'}}
Hello to Device Phidget Dial, Serial Number: 496910
{'channel': {'number': 0, 'class': 5, 'name': 'Digital Input', 'class-name': 'PhidgetDigitalInput'}, 'hub': {'number': <Phidget22.Phidget.Phidget object at 0x7f906fa54b70>, 'port-count': 6, 'port': 3}, 'parent': {'object': <Phidget22.Phidget.Phidget object at 0x7f906fa54be0>}, 'device': {'serial': 496910, 'label': '', 'version': 101, 'name': 'Phidget Dial', 'class': 21, 'sku': 'HIN1101', 'id': 109, 'class-name': 'PhidgetVINT'}}
Hello to Device Hub Port - Digital Input Mode, Serial Number: 496910
{'channel': {'number': 0, 'class': 5, 'name': 'Digital Input', 'class-name': 'PhidgetDigitalInput'}, 'hub': {'number': <Phidget22.Phidget.Phidget object at 0x7f906fa54be0>, 'port-count': 6, 'port': 0}, 'parent': {'object': <Phidget22.Phidget.Phidget object at 0x7f906fa54e48>}, 'device': {'serial': 496910, 'label': '', 'version': 100, 'name': 'Hub Port - Digital Input Mode', 'class': 21, 'sku': 'DIGITALINPUT_PORT', 'id': 95, 'class-name': 'PhidgetVINT'}}

So to summarize your previous comments:
* Device Phidget Dial is listed twice because it has two "hooks" PhidgetEncoder and PhidgetDigitalInput, classes 8 and 5, respectively? From this information, I can get the rotation info and the bush button information. Is that correct? Which is which? Is there documentation specific to a device and a programming language (e.g., Python and HIN1101_0)
* The other analog/digital devices are "not smart" in that there is no signal to identify them. From a design point of view, is it just not an extra component on each board to make this possible, that currently doesn't exist? Then VINT in parallel would work more similar to the USB protocol.
* I am creating a "scan" action for my lsphidget.py script with a 5 second timeout to capture data from these unknowable sources. I would believe each sensor will indeed have a data signature that will help me identify them. So I collect voltage changes on all "PhidgetVoltageInput" and (1) identify which one is moving [and I can manually label it] or (2) identify which one is moving and match to some signature related to the data being collected.

Am I on the right track?

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 7:33 am
by monteshaffer
Here is an update on lsphidget

Code: Select all

attachedDevice = channel
        info = {}
        info["parent"] = {}
        info["device"] = {}
        info["channel"] = {}
        info["hub"] = {}
        
        info["device"]["serial"] = attachedDevice.getDeviceSerialNumber()
        info["device"]["id"] = attachedDevice.getDeviceID()
        info["device"]["sku"] = attachedDevice.getDeviceSKU()
        info["device"]["version"] = attachedDevice.getDeviceVersion()
        info["device"]["id"] = attachedDevice.getDeviceID()
        info["device"]["label"] = attachedDevice.getDeviceLabel()
        info["device"]["name"] = attachedDevice.getDeviceName()
        info["device"]["class"] = attachedDevice.getDeviceClass()
        info["device"]["class-name"] = attachedDevice.getDeviceClassName()
        info["channel"]["number"] = attachedDevice.getChannel()
        info["channel"]["name"] = attachedDevice.getChannelName()
        info["channel"]["class"] = attachedDevice.getChannelClass()
        info["channel"]["class-name"] = attachedDevice.getChannelClassName()
        info["parent"]["object"] = attachedDevice.getParent()
        info["hub"]["number"] = attachedDevice.getHub()
        info["hub"]["port"] = attachedDevice.getHubPort()
        info["hub"]["port-count"] = attachedDevice.getHubPortCount()
and to emulate something like lsusb

Code: Select all

mstr = "CH " + str(info["channel"]["number"]).rjust(2," ") + " CL " + str(info["channel"]["class"]).rjust(2," ") + "  DE " + str(info["device"]["id"]).rjust(3," ") + "." + str(info["device"]["version"]) + " CL " + str(info["device"]["class"]).rjust(2," ") + "   " + str(info["channel"]["name"]).ljust(20," ") + " :: " + str(info["device"]["name"])
The output:

Code: Select all

CH  0 CL 13  DE  64.117 CL  8   VINT Hub             :: 6-Port USB VINT Hub Phidget
CH  0 CL  8  DE 109.101 CL 21   Encoder Input        :: Phidget Dial
CH  0 CL  5  DE 109.101 CL 21   Digital Input        :: Phidget Dial
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 29  DE  97.100 CL 21   Voltage Input        :: Hub Port - Voltage Input Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode
CH  0 CL  5  DE  95.100 CL 21   Digital Input        :: Hub Port - Digital Input Mode
CH  0 CL  6  DE  96.100 CL 21   Digital Output       :: Hub Port - Digital Output Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode
CH  0 CL 31  DE  98.100 CL 21   Voltage Ratio Input  :: Hub Port - Voltage Ratio Mode

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 8:45 am
by mparadis
It looks like you've got it working now. Answering your bullet points from the previous post:

* Yes, the Dial Phidget gets two entries because there are two unique channels. You shouldn't have to use the class ID to determine which is which, since the ChannelClassName will provide the name. You can view the API documentation for the HIN1101 on its product page- if you click on the "API" tab, you can select python from the language selector to view all methods, events and enums supported by the HIN1101 in python.

* In order to make our analog sensors "smart" it would be a matter of adding USB hardware and storage to hold firmware. From a design point of view, you are correct; it doesn't take too much to add these components. This is why many VINT sensors are revisions of previous Phidget sensors that have something similar added so they can be identified. For example 1125 -> HUM1000, 1130 -> ADP1000, 1128 -> DST1200, 1113-> HIN1100.

* Yes, in most situations you will probably be able to analyze the voltage on each port to determine in context which sensor is connected to each port.

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 9:04 am
by monteshaffer
Thanks for the responses...

I want to take your sample examples and build standalone mini-apps with logging functionality.

So the example python3 Encoder.py does some default methods to determine the device to capture data on, in this case Channel 0, Port 3.

Code: Select all

Waiting for the Phidget Encoder Object to be attached...

Attach Event Detected (Information Below)
===========================================
Library Version: Phidget22 - Version 1.0.0 - Built Feb 26 2018 19:41:25
Serial Number: 496910
Channel: 0
Channel Class: 8
Channel Name: Encoder Input
Device ID: 109
Device Version: 101
Device Name: Phidget Dial
Device Class: 21


Gathering data for 10 seconds...
Position Changed:       0  248.228  0

...

Detach event on Port 3 Channel 0
Closed Encoder device


Am I correct in understanding, this function has three identifying features: SERIAL, CHANNEL, PORT as in 496910, 0, 3 ?

Is this the same for all phidgets, or does it vary?

So if I wanted to create a python script

Code: Select all

python3 capture_Encoder.py --serial 496910 --channel 0 --port 3
and

Code: Select all

python3 capture_DigitalInput.py --serial 496910 --channel 0 --port 3
those three elements are really the only necessary components to identify correctly where to capture?

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 9:58 am
by mparadis
Serial, channel, and port is enough information to narrow down a single channel of a specific class in any situation. Some Phidgets will not have a port if they are directly connected via USB (such a a 1018 InterfaceKit), but serial and channel (and channel class) is enough in those situations.

Re: Getting Started with Python and Debian

Posted: Fri Mar 02, 2018 10:20 am
by monteshaffer
Okay, so if I plug in 1112 into a known port, e.g., Channel 0, Hub Port 2, how do I capture its voltage as a handler?

It says it is handled by VoltageRatio Input, so I tried

python3 VoltageRatio.py

but it will not obvious "attach" based on the stream of this topic...

I tried to add the following:

Code: Select all

ch.setDeviceSerialNumber(496910)
ch.setChannel(0)
ch.setHubPort(2)
as I have it plugged into hub-port 2 of my VINT hub with serial 496910.

I am obviously missing something.