I want to control the relays of the impedance meter board using python. I can toggle the relay back and forth by running my code more than once, but can't figure out how to toggle it back and forth without starting from the top. I tried using triggerPC but that won't work either.
The interesting bits:
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
if hdwf.value == hdwfNone.value:
print ("failed to open device")
quit()
def send5mspulse(hdwf, ch):
dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.005)) # 5ms run
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(ch), c_int(1))
dwf.FDwfDigitalOutIdleSet(hdwf, c_int(ch), c_int(1)) # 1=DwfDigitalOutIdleLow, low when not running
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(ch), c_int(1), c_int(0)) # initialize with high when running
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(ch), c_int(0), c_int(0))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(5.0)) # set voltage to 5 V
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable
#dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcPC)
dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(0)) # infinite repeat
dwf.FDwfDigitalOutRepeatTriggerSet(hdwf, c_int(1)) # wait for trigger in each cycle
# <-- This toggles the relay. If I change to pins 14 and 15 and re-run the code it toggles back -->
send5mspulse(hdwf, 6)
send5mspulse(hdwf, 7)
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
#dwf.FDwfDeviceTriggerPC(hdwf)
time.sleep(1)
# <--- This will not toggle back! -->
send5mspulse(hdwf, 14)
send5mspulse(hdwf, 15)
#dwf.FDwfDeviceTriggerPC(hdwf)
time.sleep(1)
dwf.FDwfDeviceCloseAll()
Question
Torbjørn
I want to control the relays of the impedance meter board using python. I can toggle the relay back and forth by running my code more than once, but can't figure out how to toggle it back and forth without starting from the top. I tried using triggerPC but that won't work either.
The interesting bits:
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == hdwfNone.value: print ("failed to open device") quit() def send5mspulse(hdwf, ch): dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.005)) # 5ms run dwf.FDwfDigitalOutEnableSet(hdwf, c_int(ch), c_int(1)) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(ch), c_int(1)) # 1=DwfDigitalOutIdleLow, low when not running dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(ch), c_int(1), c_int(0)) # initialize with high when running dwf.FDwfDigitalOutCounterSet(hdwf, c_int(ch), c_int(0), c_int(0)) dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(5.0)) # set voltage to 5 V dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable #dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcPC) dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(0)) # infinite repeat dwf.FDwfDigitalOutRepeatTriggerSet(hdwf, c_int(1)) # wait for trigger in each cycle # <-- This toggles the relay. If I change to pins 14 and 15 and re-run the code it toggles back --> send5mspulse(hdwf, 6) send5mspulse(hdwf, 7) dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) #dwf.FDwfDeviceTriggerPC(hdwf) time.sleep(1) # <--- This will not toggle back! --> send5mspulse(hdwf, 14) send5mspulse(hdwf, 15) #dwf.FDwfDeviceTriggerPC(hdwf) time.sleep(1) dwf.FDwfDeviceCloseAll()
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now