State persistence of DigitalOutputs through Network Server

Comments & issues
Post Reply
Malik
Fresh meat
Posts: 2
Joined: Wed Aug 19, 2020 9:26 am
Contact:

State persistence of DigitalOutputs through Network Server

Post by Malik »

Hello

I am trying to create a switching system with 4 solid state Phidget relays(link : https://www.phidgets.com/?prodid=1120 ) and Phidget VINT Hub( https://www.phidgets.com/?tier=3&catid= ... prodid=643) by controlling them using the Python API and I am running into a state persistency problem.
I need the relays to keep their state once I close the channels and quit the script.
I saw on this topic : viewtopic.php?t=8471 that using a Phidget may help with this problem but still can't make it work

I am now troubleshooting the problem using one of the Phidget code sample which I modified slightly to control the Phidget remotely.

The way I'm using them is the following :
1: creating 4 DigitalOutput objects and initializing them.
2: Setting the state of the desired relay to True.
3: waiting for a keyboard interruption
4: closing the DigitalOutputs and exiting the script.

Code: Select all

def main():
	#instanciantes 4 DigitalOutput Objects
	digitalOutput0 = DigitalOutput()
	digitalOutput1 = DigitalOutput()
	digitalOutput2 = DigitalOutput()
	digitalOutput3 = DigitalOutput()
	
	#ininitialize the outputs and enabling remote option
	digitalOutput0.setIsHubPortDevice(True)
	digitalOutput0.setHubPort(0)
	digitalOutput0.setIsRemote(1)
	digitalOutput1.setIsHubPortDevice(True)
	digitalOutput1.setHubPort(1)
	digitalOutput1.setIsRemote(1)
	digitalOutput2.setIsHubPortDevice(True)
	digitalOutput2.setHubPort(2)
	digitalOutput2.setIsRemote(1)
	digitalOutput3.setIsHubPortDevice(True)
	digitalOutput3.setHubPort(3)
	digitalOutput3.setIsRemote(1)
	#Search and connect to the server								 
   Net.enableServerDiscovery
     (PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)
	digitalOutput0.openWaitForAttachment(5000)
	digitalOutput1.openWaitForAttachment(5000)
	digitalOutput2.openWaitForAttachment(5000)
	digitalOutput3.openWaitForAttachment(5000)
	
	#switching ON digitalOutput2
	digitalOutput2.setState(True)
	
	time.sleep(1)
	
	#waiting for a user action to stop the script
	try:
		input("Press Enter to Stop\n")
	except (Exception, KeyboardInterrupt):
		pass
	#closing the channels 
	digitalOutput0.close()
	digitalOutput1.close()
	digitalOutput2.close()
	digitalOutput3.close()

main()
jdecoux
Labview Developer
Posts: 161
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: State persistence of DigitalOutputs through Network Server

Post by jdecoux »

The idea of using a "remote" connection to keep Phidgets open after a program is closed is to use two programs. One to keep the Phidgets alive, and one to control them.

The first program will open the Phidgets, and remain running indefinitely doing nothing else.

The second program is the one you actually intend on using to change the state, which can then exit without fear of the Phidget changing state, since it remains open in the first.
Malik
Fresh meat
Posts: 2
Joined: Wed Aug 19, 2020 9:26 am
Contact:

Re: State persistence of DigitalOutputs through Network Server

Post by Malik »

Thank you for this quick answer.
jdecoux wrote:The idea of using a "remote" connection to keep Phidgets open after a program is closed is to use two programs. One to keep the Phidgets alive, and one to control them.
Is it true also when your using the switches with Windows?
According to the documentation,the control panel and the "Bonjour for Windows" software is enough to make the relays work without losing their previous state everytime.
https://www.phidgets.com/docs/Phidget_N ... er#Windows
jdecoux
Labview Developer
Posts: 161
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: State persistence of DigitalOutputs through Network Server

Post by jdecoux »

It is true for Windows, and all other operating systems.

"Bonjour for Windows" allows your computer to find Phigdets on remote networks without necessarily needing to specify an IP address or hostname.

You need a program to actually open the Phidget if you want to keep its state. Hypothetically, you could open the control panel example for the channel and leave that running, but that's a less-than-ideal solution since you might then close it unintentionally.
Post Reply

Who is online

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