Page 1 of 1
P22 on a R-Pi question
Posted: Sat Aug 07, 2021 8:53 am
by berkinet
I have a R-Pi running the Phidget22 Network server (up-to-date) with an attached 1018 interfaceKit. In my onSensorChangeHandler, I can read sensorValue, but not sensorUnit. When I type it I get... <class 'Phidget22.UnitInfo.UnitInfo'>
Attempting to display that, even as a string, just blows up.
Ideas?
Re: P22 on a R-Pi question
Posted: Sat Aug 07, 2021 11:41 am
by berkinet
Ok, so I found the unit name as sensorUnit.name. All ok. Just one question, where is that documented? The API pages do not show that.
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 8:08 am
by mparadis
In the API, if you click on "UnitInfo" in the return type, it brings you to the class description and it lists out the members there.
Also, when I print sensorUnit like this:
Code: Select all
sensorUnit = ch.getSensorUnit()
print("SensorUnit: " + str(sensorUnit))
This is the output I get:
Code: Select all
SensorUnit: [UnitInfo] (unit: 12, name: volt, symbol: V)
Which is another way to get the members. The fact that your output only says "<class 'Phidget22.UnitInfo.UnitInfo'>" seems to be an indicator that you have an outdated Phidgets python module. This issue is also apparent in the other post you made about printing the channel handle- an up-to-date version of the python module will print out a more reasonable human-readable string rather than <Phidget22.Phidget.Phidget instance at 0x1011b2ea8>.
I actually had the same issue earlier- I thought I was running an up-to-date version of the python module but my python installation was pulling an old version of the library from another folder. I wasn't able to fix the problem using pip because the library had been installed outside of pip so I had to track it down, manually delete it, and then use pip to install and update to the newest version of the module.
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 8:53 am
by berkinet
Once again, thanks for the response. I am using a copy of the libs embedded in the plugin I am writing. So, I should not be getting issues with the system install. But, I will update to be sure. Question: Is there a way to tell the version of the libs I am using in a program?
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 9:26 am
by mparadis
Just to be clear, it's not the Phidget22 OS drivers, but the Phidget22 python package version.
You can see the version you're using if you type "pip show" in the command line. The current version is 1.7.20210706.
If you don't use pip, you can use type "python" in the command line and then type
Code: Select all
import pkg_resources
pkg_resources.get_distribution('Phidget22').version
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 9:28 am
by berkinet
Thanks... but, that gets me the version installed for the system. Which, as you note, I can get from pip. I wanted to get the version of a copy of the libs I have embedded in my plugin project.
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 9:42 am
by mparadis
Oh, I'm not sure if there's a command to get the version in that case. If you can locate the PKG-INFO file for the package you can read it from there, if there's a visible file structure.
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 9:57 am
by berkinet
Hmmm... well, I found I can get the library version like this
Code: Select all
print(phidget.getLibraryVersion())
version: Phidget22 - Version 1.7 - Built Jul 6 2021 11:31:54
But, that requires creating a phidget object first. Is there, maybe, a way to get that without first creating an object?
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 10:05 am
by Patrick
phidget.getLibraryVersion() is giving you the phidget22 C library version, not the Python library version. The Python library is a wrapper around the C library.
Re: P22 on a R-Pi question
Posted: Mon Aug 09, 2021 10:07 am
by berkinet