Jump to content
  • 0

FDwfDeviceOpen disables power supply on Analog Discovery 2


DurandA

Question

I am trying to automate some tests using different supply voltages.

First, I am using dwfcmd to set a voltage during the setup phase:

dwfcmd connect analogio channel=1 enable=1 voltage=1.15 masterenable=1 disconnect

Then I use a Python script to vary the voltage:

from dwfconstants import *

dwf = cdll.LoadLibrary("libdwf.so")
hdwf = c_int()

print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

if hdwf.value == hdwfNone.value:
    print("failed to open device")
    quit()

time.sleep(5)

dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.20))
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))

However, calling FDwfDeviceOpen() disables the power supply. In the example above, I inserted a 5 sec sleep, which means there is no power during more than 5 seconds.

How can access the Analog Discovery 2 from Python without disabling the power supply?

Edit: I tried to remove disconnect from dwfcmd args and reuse the hdwf handle which just seems to be the enumeration id (always 1 in my case). However, the last line of dwfcmd.cpp is FApi("FDwfDeviceCloseAll", FDwfDeviceCloseAll());. I tried recompiling dwfcmd without this line using "g++ -o dwfcmd_noclose -I/usr/include/digilent/waveforms/ dwfcmd.cpp -ldwf" but once compiled it fails:

pure virtual method called
terminate called without an active exception
Aborted (core dumped)

It seems that this error happens whenever FDwfDeviceClose is not called, including outside of dwfcmd.

Edited by DurandA
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hi @DurandA

Use the following in all apps and scripts using the device:

...
dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = run, 1 = stop, 2 = shutdown
dwf.FDwfDeviceOpen(...
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0)) # 0 = the device will be configured only when calling FDwf###Configure
...
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.20))
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))
dwf.FDwfAnalogIOConfigure(hdwf)
...
dwf.FDwfDeviceClose...

 

Link to comment
Share on other sites

  • 0

Hi @attila

Unfortunately your solution does not work. The power supply still shuts down during the second FDwfDeviceOpen() for about 1 second. Here is a minimal script to reproduce the issue:

from ctypes import *
from dwfconstants import *

dwf = cdll.LoadLibrary("libdwf.so")
hdwf = c_int()

dwf.FDwfParamSet(DwfParamOnClose, c_int(0))
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.15))
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))
dwf.FDwfAnalogIOConfigure(hdwf)
dwf.FDwfDeviceClose(hdwf)
# start over
dwf.FDwfParamSet(DwfParamOnClose, c_int(0))
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # power shut down during ~ 1 sec
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True))
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.15))
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))
dwf.FDwfAnalogIOConfigure(hdwf)
dwf.FDwfDeviceClose(hdwf)

Thank you for your help.

Link to comment
Share on other sites

  • 0

Hi @DurandA

I don't notice any shutdown with latest WF version 3.16.3 or 3.16.31
https://reference.digilentinc.com/reference/software/waveforms/start
https://forum.digilentinc.com/topic/8908-waveforms-beta-download/

image.thumb.png.7fa5df95701b1f53860e661f4d559677.png

 

from ctypes import *
import sys
import time
from dwfconstants import *

if sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("dwf")

hdwf = c_int()

dwf.FDwfParamSet(DwfParamOnClose, c_int(0))

for i in range(10):
    dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
    if hdwf.value == 0:
        print("failed to open device")
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()

    dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))
    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(1))
    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.0+i/2))
    dwf.FDwfAnalogIOEnableSet(hdwf, c_int(1))
    dwf.FDwfAnalogIOConfigure(hdwf)
    dwf.FDwfDeviceClose(hdwf)

 

image.thumb.png.bc08782d2d1040f71551f07c2bc10e96.png

from ctypes import *
import sys
import time
from dwfconstants import *

if sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("dwf")


cDev = c_int()
dwf.FDwfEnum(0, byref(cDev))
if cDev == 0:
    print("no device detected")
    quit()

dwf.FDwfParamSet(DwfParamOnClose, c_int(0))

hdwf = c_int()

for i in range(10):
    dwf.FDwfDeviceOpen(c_int(0), byref(hdwf))
    if hdwf.value == 0:
        print("failed to open device")
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()

    dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))
    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(1))
    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(1.0+i/2))
    dwf.FDwfAnalogIOEnableSet(hdwf, c_int(1))
    dwf.FDwfAnalogIOConfigure(hdwf)
    dwf.FDwfDeviceClose(hdwf)

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...