openRemoteIP - I suspect there's a quick answer.

Supporting 2.7 and 3.2+
Lyndon Williams
Phidgetsian
Posts: 9
Joined: Tue Nov 27, 2012 7:25 am
Contact:

openRemoteIP - I suspect there's a quick answer.

Post by Lyndon Williams »

I used an 1124 temperature sensor on an 8/8/8 interface board locally. Here's a very simple code that worked.....

Code: Select all

from Phidgets.Devices.InterfaceKit import InterfaceKit

localIFK= InterfaceKit()

localIFK.openPhidget()
localIFK.waitForAttach(10000)

sensorvalue = localIFK.getSensorValue(0)

roomtemp = (int)((sensorvalue * 0.22222) - 61.11);

print ("The temperature in this room is: %d" %roomtemp)

Then I put the 1124 on a remote sbc and tried it again.

Code: Select all

from Phidgets.Devices.InterfaceKit import InterfaceKit

remoteIFK= InterfaceKit()

remoteIFK.openRemoteIP("192.168.83.142",5001,"")
remoteIFK.waitForAttach(10000)

sensorvalue = remoteIFK.getSensorValue(0)

roomtemp = (int)((sensorvalue * 0.22222) - 61.11);

print ("The temperature in this room is: %d" %roomtemp)
But Python tells me....

Traceback (most recent call last):
File "C:\Python32\simpleTemperaturSensor.py", line 6, in <module>
remoteIFK.openRemoteIP("192.168.83.142",5001,"")
File "C:\Python32\lib\site-packages\Phidgets\Phidget.py", line 399, in openRemoteIP
result = PhidgetLibrary.getDll().CPhidget_openRemoteIP(self.handle, c_int(serial), c_char_p(IPAddress), c_int(port), c_char_p(password))
TypeError: bytes or integer address expected instead of str instance


I'm sure there is a very simple answer. Can anyone help?
User avatar
burley
Human-Cyborg Relations
Posts: 26
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by burley »

openRemoteIP has 4 arguments. You have left out serial number.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com
Lyndon Williams
Phidgetsian
Posts: 9
Joined: Tue Nov 27, 2012 7:25 am
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by Lyndon Williams »

Hey Brian,

I tried adding the serial number as the third argument. Here is the code....

Code: Select all

from Phidgets.Devices.InterfaceKit import InterfaceKit

remoteIFK= InterfaceKit()

remoteIFK.openRemoteIP("192.168.83.142",5001,45240,"")
# remoteIFK.openRemoteIP(45240,"192.168.83.142",5001,"")

remoteIFK.waitForAttach(10000)

sensorvalue = remoteIFK.getSensorValue(0)

roomtemp = (int)((sensorvalue * 0.22222) - 61.11);

print ("The temperature in this room is: %d" %roomtemp)

I receive the same error. I even put it in as the first argument, which might be inferred from the error message. What am I overlooking here?

The piece in the API document made me believe that serial number could be left out. Here is the excerpt....
openRemoteIP(self, IPAddress, port, serial=-1, password='')
Open this Phidget remotely using an IP Address, securely providing a password,and whether or not to connect to a specific serial number.

Providing a password will open the connection securely depending on if a password is set on the host machine's webservice.

If no serial number is provided, the first available Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as there is no guarantee which Phidget will be selected by the call to open().

Parameters:
IPAddress<string>: IP Address or hostname of the Phidget Webservice
port<int>: Port of the Phidget Webservice
serial<int>: The serial number of the device
password<string>: The secure password for the Phidget Webservice

Exceptions:
RuntimeError - If current platform is not supported/phidget c dll cannot be found
PhidgetException: if the Phidget Webservice cannot be contacted
User avatar
burley
Human-Cyborg Relations
Posts: 26
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by burley »

Try running this though obviously replace the IP address with the appropriate one. It is just a simple modification of our default sample code:

Code: Select all

#!/usr/bin/env python

#Basic imports
from ctypes import *
import sys
import random
#Phidget specific imports
from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs
from Phidgets.Devices.InterfaceKit import InterfaceKit

#Create an interfacekit object
try:
    interfaceKit = InterfaceKit()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Event Handler Callback Functions
def inferfaceKitAttached(e):
    attached = e.device
    print("InterfaceKit %i Attached!" % (attached.getSerialNum()))

def interfaceKitDetached(e):
    detached = e.device
    print("InterfaceKit %i Detached!" % (detached.getSerialNum()))

def interfaceKitError(e):
    try:
        source = e.device
        print("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))

def interfaceKitInputChanged(e):
    source = e.device
    print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))

def interfaceKitSensorChanged(e):
    source = e.device
    print("InterfaceKit %i: Sensor %i: %i" % (source.getSerialNum(), e.index, e.value))

def interfaceKitOutputChanged(e):
    source = e.device
    print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))

#Main Program Code
try:
    interfaceKit.setOnAttachHandler(inferfaceKitAttached)
    interfaceKit.setOnDetachHandler(interfaceKitDetached)
    interfaceKit.setOnErrorhandler(interfaceKitError)
    interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
    interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
    interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Opening phidget object....")

try:
    interfaceKit.openRemoteIP("192.168.3.197",5001, -1, "")
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Waiting for attach....")

try:
    interfaceKit.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        interfaceKit.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
	print("Press Enter to quit....")

chr = sys.stdin.read(1)

print("Closing...")

try:
    interfaceKit.closePhidget()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Done.")
exit(0)
This works on my machine.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com
Lyndon Williams
Phidgetsian
Posts: 9
Joined: Tue Nov 27, 2012 7:25 am
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by Lyndon Williams »

I received the same error. Are you running Python 3.2 or 2.7?


Traceback (most recent call last):
File "C:\Python32\simpleTemperaturSensor.py", line 64, in <module>
interfaceKit.openRemoteIP("192.168.83.142",5001, -1, "")
File "C:\Python32\lib\site-packages\Phidgets\Phidget.py", line 399, in openRemoteIP
result = PhidgetLibrary.getDll().CPhidget_openRemoteIP(self.handle, c_int(serial), c_char_p(IPAddress), c_int(port), c_char_p(password))
TypeError: bytes or integer address expected instead of str instance
User avatar
burley
Human-Cyborg Relations
Posts: 26
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by burley »

I've got both 2.6 and 3.2.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com
heritagerobotics
Fresh meat
Posts: 1
Joined: Wed Nov 21, 2012 6:30 am
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by heritagerobotics »

We have tried and tried and tried on any number of machines with the very code that burley provides, and we get the same error every time.....


>>>
Opening phidget object....
Traceback (most recent call last):
File "C:\Python32\SBC-Temp-Test.py", line 64, in <module>
interfaceKit.openRemoteIP("192.168.83.33",5001, -1, "")
File "C:\Python32\lib\site-packages\Phidgets\Phidget.py", line 399, in openRemoteIP
result = PhidgetLibrary.getDll().CPhidget_openRemoteIP(self.handle, c_int(serial), c_char_p(IPAddress), c_int(port), c_char_p(password))
TypeError: bytes or integer address expected instead of str instance
>>>



Is there no one who knows what the problem is or what we can do to fix it?
Lyndon Williams
Phidgetsian
Posts: 9
Joined: Tue Nov 27, 2012 7:25 am
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by Lyndon Williams »

The error only occurs for me with Python 3.2 or Python 3.3, not with Python 2.7.
User avatar
burley
Human-Cyborg Relations
Posts: 26
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by burley »

Lyndon Williams wrote:The error only occurs for me with Python 3.2 or Python 3.3, not with Python 2.7.
It does appear to be a 3.2 related error.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com
Lyndon Williams
Phidgetsian
Posts: 9
Joined: Tue Nov 27, 2012 7:25 am
Contact:

Re: openRemoteIP - I suspect there's a quick answer.

Post by Lyndon Williams »

The same error occurs in Python 3.3 as well. It seems to be something with the ctypes module with Python 3.X, or some out of date coding in C:\Python32\lib\site-packages\Phidgets\Phidget.py.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests