Page 1 of 1

relay control

Posted: Tue Feb 28, 2023 8:16 am
by buzz
Hello. I'm trying to understand why channel getState() always reports FALSE even if I know (and can verify) that I've ordered a relay port to be closed. I'm using a four port relay board. PhidgetInterfaceKit 0/0/4, 1014_2

Python:

Code: Select all

for i in range(count):
    ch = DigitalOutput()
    ch.setDeviceSerialNumber(576878)
    ch.setChannel(i)
    ch.openWaitForAttachment(1000)
    state = ch.getState()
    dutyCycle = ch.getDutyCycle()
    ch.close()
    print("port ", i, " State: " + str(state), " Duty cycle ", str(dutyCycle))
close one of the relays using the command line tools:

Code: Select all

/usr/local/bin/phidutil2 -p 1 1
Output is always false, no matter what if any of the relay ports are set open or closed via phidutil2:

Code: Select all

port  0  State: False  Duty cycle  0.0
port  1  State: False  Duty cycle  0.0
port  2  State: False  Duty cycle  0.0
port  3  State: False  Duty cycle  0.0

Re: relay control

Posted: Tue Feb 28, 2023 8:59 am
by mparadis
It looks like you're printing the state of the relay immediately after opening it. The state of a digital output object is always false when it is first opened, regardless of what state it was in when it was last closed. In fact, all Phidget channels will have all of their properties at their default value when you first open them.

This means that if you want to keep the relay state "true", the program needs to keep running.