To download NI software, including the products shown below, visit ni.com/downloads.
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.
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:
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Hello,
I am trying to build a script based off of this but having one issue. When I try to collect the data at smaller frequency (say 2 Hz), this script (and even LabVIEW for that matter) does not collect data at the desired frequency. I am using cDAQ-9185 and NI 9202 with DSUB module. Am I not able to understand something that is happening here? Why can't I collect the voltage data at 2Hz?
Thank you,
Dushyant
Hello, thank you very much for sharing your method. I have a question. Python is often said to have a slower execution speed. If there are multiple channels and each channel samples at a sampling frequency of over 100kHz, is it still feasible to use Python for data acquisition?
Hi David,
I added some code on your example to include the choice of physical channels as a drop down of options available in NI MAX in combobox. I removed the physicalChannelEntry and replace it with combobox. The list of the devices can be obtained using the nidaqmx.constant package.
import nidaqmx.system
def create_widgets(self):
sys = nidaqmx.system.System.local()
physical_channel_list = [""]
for dev in sys.devices:
for physical_channel in dev.ai_physical_chans:
physical_channel_list.append(physical_channel.name)
self.physicalChannelLabel = ttk.Label(self, text="Physical Channel")
self.physicalChannelLabel.grid(row=0, sticky='w', padx=self.xPadding, pady=(10, 0))
self.physicalChannelComboBox = ttk.Combobox(self)
self.physicalChannelComboBox['values'] = physical_channel_list
self.physicalChannelComboBox.current(1)
self.physicalChannelComboBox.grid(row=1, sticky="ew", padx=self.xPadding)