nidaqmx-python | A Python API for interacting with NI-DAQmx | REST library
kandi X-RAY | nidaqmx-python Summary
kandi X-RAY | nidaqmx-python Summary
A Python API for interacting with NI-DAQmx
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Read from the stream
- Convert a parameter to a string
- Wrap ndpointer
- Read data from an analog channel
- Write data to the stream
- Write a 64 bit array to a dask array
- Writes a frequency freq to the task handle
- Write ticks to the task
- Create a CILinEncoder channel
- Reads an unsigned 32 - bit integer from the stream
- Reads an integer value from the stream
- Reads an integer from the stream
- Adds an AIOS LVDT channel
- Creates a CNG encoder channel
- Creates a new AIAccel4 WireDCVoltage Channel
- Reads an unsigned integer from the stream
- Adds a rosettelli strain to a channel
- Creates a new AITorque bridge table channel
- Creates a new AI force bridge
- Add an Ip pressure bridge
- Add an I - torque channel polynomial channel
- Creates a PA Pressure bridge table
- Creates an AI force bridge table channel
- Adds an A force bridge to a channel
- Creates a new API pressure bridge
- Add a two - point AITor bridge to a specific channel
nidaqmx-python Key Features
nidaqmx-python Examples and Code Snippets
Community Discussions
Trending Discussions on nidaqmx-python
QUESTION
I have seen other questions on the topic on this forum, but none have helped me understand how to deal with this. Most of them also seem to me to be about quite intricated and long code. I believe I am doing something rather simple / would like to do something rather simple. I hope someone can help! Here below extensive explanations and then my current code.
NOTE: please do not delete this question. I have given the following a lot of thought and I have carefully gone through related threads, but to no avail. I also believe it makes sense to post this because it is partly related to a more generic question: that of how to plot in real-time while having callbacks running in the background (see summary at the end), which could be summarized to be my general goal.
Setup and goal: National Instruments acquisition module (this matters litlle) NI cDAQ9178, interfaced via nidaqmx-python
, a package maintained by NI with documentation here. Some analog signal is inputed in there, and the goal is to acquire it continuously (until I decide to stop the acquisition) at a certain sampling rate (approximately 1000 Hz) while plotting the signal in real time. The plotting needs not be refreshed nearly so often (10Hz refresh rate would even be fine). I'm using Windows 10 with Python 3.7 in a conda virtual environment, and editing is done in PyCharm. Ideally things should work both in PyCharm and any terminal.
Situation: nidaqmx-python
provides high-level functions that allow one to register callbacks (which one defines as one wishes), which are called everytime a certain number of samples (in my case 100, but that's not strict) fills the PC buffer. The idea is that the callback, defined below, reads the buffer at that point, and does something (in my case some low-pass filtering, which I have taken out for conciseness, some storing into a global variable data
, and maybe plotting - see below).
Problem: I have been fooling around with having whatever plots the data in real time be included in the callback, but with matplotlib that is a nightmare because the callback uses threads other than the main one, and matplotlib does not like to be called from anywhere outside the main thread. I've googled the heck out of other libraries optimized for real-time plotting (and, I was thinking, hopefully thread safe) but it's not so easy: I cannot get vispy to work and I cannot get pyqtgraph to even install, just to give you some examples. Then I saw several posts on the internet of people actually managing pretty decent real-time animations with matplotlib, despite it having been developped with publication in mind and not these applications; so I thought let's give it a go.
My take: Since I could not have matplotlib do the work from inside the callback, I did the following (which is the code you see below): after the callback and after the task is started with task.start()
(that's specific to nidaqmx-python
), I just create a while
loop which plots the global variable buffer
. I thought it was a nice trick: see, buffer
is updated (call it that) by the callback every 0.1 seconds or so (does not matter) and, on the side, the while
loop is plotting the buffer
variable over and over, erasing everytime before plotting, effectively yielding a real-time like plot.
NOTE: I am perfectly aware the plotting part is not nearly as good as it could be made (I probably should use the ax API of matplotlib and the subplots
, not to mention animation), but I do not care for the moment. I'll deal with that later and refine it to make it more efficient.
What I want: this actually does what I want ... except, in order to stop it, I introduced the try:
and except:
statements around the while
loop, as you see in the code below. Naturally, pressing CTRL+C
does break the loop ... but it then also breaks the whole running script and leaves me with the following error: forrtl: error (200): program aborting due to control-C event
, in PyCharm, and the following precision when run from a terminal:
ANSWER
Answered 2020-Apr-03 at 19:50The first thing I did was get rid of the keyboard interrupt loop. I replaced it with a global variable running
, and another thread that sets the variable to False
when returned from.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nidaqmx-python
You can use nidaqmx-python like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page