Virus scan in progress. Please wait to download attachments.
NI offers various Python drivers for its hardware, such as NI-DAQmx. I thought it would be nice to create the Voltage - Continuous Input shipping example using Python. A demonstration video of a replicated version made using Python is shown below.
The GUI is built using Tkinter and Matplotlib. I tried to emulate the LabVIEW shipping example as closely as possible. Once everything is positioned properly on the window, the user can start the acquisition. The GUI will poll the task until the required number of samples are available to read. The task will stop and be closed when the user presses the stop button.
Once these are installed, you can download the two attached files and place them in a folder next to each other.
Run the Python application in an IDE or text editor of your choice. During development, I used Sublime Text. You can run Python scripts from the editor with the shortcut ctrl+b defined in the Tools dropdown menu of Sublime.
Insure that you have a device in NI MAX that has an analog input channel and that it is listed in the Physical Channel entry box of the Python GUI.
Click Start Task to begin acquiring data.
Additional Information or References
Please feel free to suggest additional improvements and best practices. I would really appreciate any and all advice. My class architecture felt a little clumsy, but the different classes I had could easily be reused in other programs down the road. I also thought of several minor improvements that may or may not be made before the code is submitted for review:
There is no error handling for improper user inputs or NI-DAQmx exceptions.
The choice of physical channels is not a drop down of options available in NI MAX.
Additional settings and trigger options are missing that are present in the LabVIEW example.
The start and stop button should probably belong to the graph class.
The stop button should be disabled unless the task is running.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.