P22 on a R-Pi question

Supporting 2.7 and 3.2+
Post Reply
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

P22 on a R-Pi question

Post 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?
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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.
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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?
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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.
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post 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?
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: P22 on a R-Pi question

Post 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.
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: P22 on a R-Pi question

Post by berkinet »

:-(
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests