Jump to content
  • 0

GUI to control Analog Discovery 2


Adam1973

Question

Hi all. Hope you are all well. Can anyone please give me a recommendation of any software to develop a GUI to control the Analog Discovery 2. I have seen QTdesigner but cannot find any examples. An application and examples would be much appreciated.

Many thanks 

Adam

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Hi Adam,

 

What do you want your GUI to do? (And, especially, why does the Waveforms GUI not cover your needs?)

What language do you want to use, and how experienced a developer are you in that language? Developing a good GUI is not a simple task.

Link to comment
Share on other sites

  • 0

Hi Reddish. I am controlling an SPI enabled switch which is going to be used to test voltages developed by a system. I need a GUI to be able to input serial number of EUT and measure the voltages and record the results. I then need to print a test certificate when the EUT has passed.

Thanks Adam

Link to comment
Share on other sites

  • 0

Okay, that sounds like a small job for somebody who is properly experienced with making GUIs and knows the AD2 well. But those skills take a lot of experience to master, so your effort will greatly depend on your experience. If you start from zero, proper GUI development in any framework can take months or more to learn, and the AD2 specifics will take days to weeks to learn; and those assume that you are already a somewhat capable programmer to start with.

Personally I would implement this in Python with one of the Qt bindings (PyQt or PySide) for the GUI, and my own pydwf package to drive the AD2. Because I know those very well, I could probably implement something usable in a day or two.

Only if you tell me a bit more about your own current experience level in programming and GUI development can I estimate how long it would take you.

Cheers, Sidney

Link to comment
Share on other sites

  • 0

Hi Reddish. Thanks a lot for the reply. I am an electronics engineer with 30 years experience and have done quite a bit of embedded software over the years. I started this week with Python PYscripter and have code to communicate with the AD2. Setting IO, Reading voltages and writing to text file etc. I have done a bit of VB over the years but guess I am a novice really 

Thanks 

Adam 

Link to comment
Share on other sites

  • 0

Ok. In your place I'd consider writing an old-fashioned text-based program at first -- GUI stuff really has quite a learning curve in Python. That will make your life a lot easier and it could do everything that you need, I think, even if it looks a bit old-school.

The go-to framework for GUIs in Python is Qt (via one of its bindings, PyQt or PySide).

The challenge with learning Qt is that your program will turn into something that's event-driven -- you set up the GUI elements, connect signals (events) to slots (event handler routines), then hand over control of your main thread to Qt. It will take some getting used to, but your application is as simple as it gets, so it would be a great opportunity to play around with Qt.

I'd advice staying away from QtDesigner for now -- it adds a layer of complexity that will just complicate stuff at first. Using it effectively sort-of presumes you have a good handle on how Qt works, and the way to learn that at first is to implement a small GUI programatically, and your program is perfectly suited for that. Just setting up the small GUI you need (a single window, a few input fields, and a few buttons) is probably ~ 25 lines of code.

You could have a look at pydwf (https://pydwf.readthedocs.io/en/latest/welcome.html) to make your life easier with the AD2 stuff, but I guess if you have that working already there is little reason to do that.

Link to comment
Share on other sites

  • 0

Hi Adam,

Boring saturday evening ... so I cooked up a simple Qt application to get you started, see attachment.

This uses PySide6 (the most recent version of the Qt binding for Python) and pydwf to talk to the Analog Discovery. On a recent Python 3 distribution, "pip3 install PySide6 pydwf" should bring in all dependencies that you need.

I didn't implement printing because that can get quite involved, but it has a simple "save report to file" instead.

I hope this is useful.

 

simple_qt_ad2_program.py

Edited by reddish
Link to comment
Share on other sites

  • 0

Hi Sidney. Hope all is well. I have had a look at the code you sent and it runs but when I get measurement I am expecting 1.5 V yes? I get pretty much 0 V. Also you talk about first analog in and out channels. Are these the power supplies and scope channels respectively? 

Thanks 

Adam

Link to comment
Share on other sites

  • 0

Ah I just found it :) The voltage is on W1 of the analog discovery 2. It works :) Another question please. Do you have examples of controlling the power supplies and static IO. I have functions which work but when I call them from within the class It does not seem to work. 

def set_psu(v1,v2):  

   # set up analog IO channel nodes     # enable positive supply

    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True))     # set voltage to 5 V     dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(v1))     # enable negative supply     dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True))     # set voltage to -5 V     dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(v2))     # master enable

    dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))

    print ("Setting PSU")

    return 

 

def set_io():     # Turn on IO pins

    # Open device

    # enable output/mask on 4 LSB IO pins, from DIO 0 to 3

    dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x000F))     # set value on enabled IO pins

    #dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x20)) # IO 5 on

    time.sleep(2)

    dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x04)) # IO 2 on

    time.sleep(2)

    #dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x08)) # IO 3 on

    #time.sleep(2)

    #dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x00)) # all IO Off

    print ("Setting IO")

    time.sleep(2)

    #dwf.FDwfDeviceCloseAll()

    return

 

 

Edited by Adam1973
Link to comment
Share on other sites

  • 0

Hi @Adam1973

> I have functions which work but when I call them from within the class It does not seem to work

Are you just inserting your code into the example program by any chance? That won't work.

My program uses the "pydwf" package to interface to the AD2, whereas the code you show above uses the low-level API that's officially supported by Digilent but a lot less nice, since you have to handle all the type-conversions explicitly.

Unfortunately, Digilent does not really provide a Python binding; instead they provide the C-based API and a bunch of examples that show how to talk to the C library from Python using the Python 'ctypes' module. A proper Python binding would encapsulate that low-level stuff. The "pydwf" package does precisely that (and some more stuff, like nice examples and better documentation).

So I recommend you consider using pydwf for your code -- it is much less error-prone and the code will look a lot nicer. (Full disclosure: I made pydwf so I am pretty biased :-)).

Here's the documentation of the AnalogIO and DigitalIO functionality that comes with pydwf:

https://pydwf.readthedocs.io/en/latest/pydwf_api/DwfDevice.analogIO.html

https://pydwf.readthedocs.io/en/latest/pydwf_api/DwfDevice.digitalIO.html

Here's a page with Python examples that come with pydwf:

https://pydwf.readthedocs.io/en/latest/background/Examples.html

In particular, the AnalogIO.py and DigitalIO.py examples should get you started on how to use that functionality in pydwf. 

On the other hand, if you decide to stick with doing the ctypes stuff by hand, you should remove the "pydwf" stuff from the Qt program and just implement the functionality you need in the low-level ctypes style. It is not a good idea to mix direct ctypes-based access to the library with using "pydwf".

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...