[Solved]Open hub vin error

Supporting 2.7 and 3.2+
Post Reply
max246
Fresh meat
Posts: 2
Joined: Wed Dec 22, 2021 5:44 am
Contact:

[Solved]Open hub vin error

Post by max246 »

I have read different guides and I am struggling to get this working.

Basically I have SBC device and I have created a project which I want to access to my Digital input on Port 0.

I have this sensor connected: https://www.phidgets.com/?tier=3&catid= ... prodid=399
Using the web interface of the SBC, I can access the status and see it changing correctly, so I know that wiring and system is fully working.

Now I want to access to Digital Input on port 0 using Python, I have used the code generator on the website and set my serial number, hub port and IP of my server ( which is localhost anyway but I used the IP )


I read on other posts that if I am running a web interface on SBC, I need to use setIsRemote otherwise it wont be able to access the VIN Hub so I did so.


Code: Select all

from Phidget22.Phidget import *
from Phidget22-Net import *
from Phidget22-Devices.Log import *
from Phidget22-LogLevel import *
from Phidget22-Devices.DigitalInput import *
import time

def onDigitalInput0_StateChange(self, state):
	print("State: " + str(state))

def main():
	Log.enable(LogLevel.PHIDGET_LOG_INFO, "phidgetlog.log")
	Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)

	digitalInput0 = DigitalInput()

	digitalInput0.setHubPort(0)
	digitalInput0.setIsRemote(True)
	digitalInput0.setDeviceSerialNumber(592908)

	digitalInput0.setOnStateChangeHandler(onDigitalInput0_StateChange)

	digitalInput0.openWaitForAttachment(20000)

	time.sleep(5)

	digitalInput0.close()

main()
Output of the script:
root@phidgetsbc:/usr/userapps/framewalk# python3 s4-py


Traceback (most recent call last):
File "s4-py", line 29, in <module>
main()
File "s4-py", line 23, in main
digitalInput0.openWaitForAttachment(20000)
File "/usr/local/lib/python3.5/dist-packages/Phidget22/Phidget-py", line 574, in openWaitForAttachment
raise PhidgetException(result)
Phidget22.PhidgetException.PhidgetException: PhidgetException 0x03 (Timed Out)
No matching devices were found to open. Make sure your device is attached, and that your addressing parameters are specified correctly. If your Phidget has a plug or terminal block for external power, ensure it is plugged in and powered.
Make sure to enable server discovery, or add the server, and to set the server password if autentication is enabled.

Log file
# cat phidgetlog.log
2021-12-22T12:12:55 <Info> phidget22 :
****************************** Logging Enabled ******************************
* Phidget22 - Version 1.8 - Built Dec 2 2021 22:01:14 *
* Release 1.8 - Linux (32-bit) *
*******************************************************************************
2021-12-22T12:12:55 <Info> phidget22net[PhidgetNet_start()] : Starting Networking
2021-12-22T12:12:55 <Info> phidget22net[deviceServerListener()] : Discovered server 'srvframe' [srvframe] (interface 0x2)
2021-12-22T12:12:55 <Info> phidget22netctl[PhidgetNet_discoveredServer()] : Discovered Server: srvframe
2021-12-22T12:12:55 <Info> phidget22net[deviceServerListener()] : Discovered server 'srvframe' [srvframe] (interface 0x2)
2021-12-22T12:12:55 <Info> phidget22netctl[runNetworkControlEntry()] : network control entry thread started - srvframe: 0xb4cff470
2021-12-22T12:12:55 <Info> phidget22netctl[PhidgetNet_discoveredServer()] : Discovered Server: srvframe
2021-12-22T12:12:55 <Info> phidget22netctl[runNetworkControlEntry()] : network control entry srvframe not connected (failures=0)
2021-12-22T12:12:55 <Info> phidget22netctl[PhidgetNet_discoveredServer()] : network control entry for srvframe rediscovered
2021-12-22T12:12:55 <Info> phidget22netctl[runNetworkControlEntry()] : network control entry srvframe: connecting to srvframe (192.168.50.155:5661)
2021-12-22T12:12:55 <Info> phidget22[deviceAttach()] : (Attach) HUB0004 (6-Port PhidgetSBC VINT Hub Phidget) v203 S/N:592908
2021-12-22T12:12:55 <Info> phidget22[populateAttachedSPIDevices()] : Found SPI VINT Hub: 0x0001, 203, 592908
2021-12-22T12:12:55 <Info> phidget22usb[PhidgetUSBScanDevices()] : Initializing libusb
2021-12-22T12:12:55 <Info> phidget22net[clientConnect()] : Starting client connection to '192.168.50.155:5661'
2021-12-22T12:12:55 <Info> phidget22net[startClientConnection()] : server handshake 'phid22device' 2.3
2021-12-22T12:12:55 <Info> phidget22net[startClientConnection()] : connected to server 'srvframe'
2021-12-22T12:12:55 <Info> phidget22netctl[runNetworkControlEntry()] : network control entry srvframe connected to srvframe:5661
2021-12-22T12:12:55 <Info> phidget22[deviceAttach()] : (Attach) HUB0004 (6-Port PhidgetSBC VINT Hub Phidget) v203 S/N:592908 -> srvframe
2021-12-22T12:12:55 <Info> phidget22net[handleDeviceClientRequest()] : server netconnclient://192.168.50.155:5661 starting DATAGRAM as requested
2021-12-22T12:12:55 <Info> phidget22[deviceAttach()] : (Attach) Dictionary (Dictionary) v100 S/N:2 Label:Phidget22 Control -> srvframe
There is no evidence that it cant access because it says it has done the handshake but I cant understand how to read the sensor state from python.

Any clue?
Last edited by max246 on Wed Dec 22, 2021 9:05 am, edited 1 time in total.
fraser
Engineering
Posts: 138
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: Open hub vin error

Post by fraser »

Looks like you will want to add:

Code: Select all

digitalInput0.setIsHubPortDevice(True)
when addressing the device prior to opening it. The IsHubPortDevice property is used to differentiate between opening a channel that directly monitors the wire on the VINT port, versus opening an addressable VINT device on the same port.
max246
Fresh meat
Posts: 2
Joined: Wed Dec 22, 2021 5:44 am
Contact:

Re: Open hub vin error

Post by max246 »

wow that was a quick fix!

I scratched my head for hours to see if I did something wrong... but this solved the issue :)

I just saw this link now about that setting, handy to understand it but bit bad for the "example code" that didnt mention it.

https://www.phidgets.com/docs/Addressing_Phidgets
fraser
Engineering
Posts: 138
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: [Solved]Open hub vin error

Post by fraser »

Good point, I will poke the bear
Post Reply

Who is online

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