03-22-2011 02:52 PM
Hi all!
I want to update a traditional (legacy) nidaq system into daqmx.
In the old software there is a Config_ATrig_Event_Message function, and I can't figure it out, how to convert this function into daqmx. I spent hours to look for some usable info about it in the daqmx c help, without success. (I think, the key function is DAQmxRegisterSignalEvent with DAQmx_Val_ChangeDetectionEvent option, but I don't know how to apply it...)
So, I need a tiny daqmx code, that triggers a callback event when an AI channel (let's say AI0) goes up to 5V.
Can anybody help me?
- George -
Solved! Go to Solution.
03-23-2011 11:00 AM
Hi George,
Looking at the events that are generated by the DAQmxRegisterSignalEvent, the Change Value Detection Event does not give you the information you need about the analog voltage level.
What I found to be more useful is the Done event. If you configure a dummy task to start on an analog trigger, it will finalize execution after the trigger occured, or else return an error. Since you don't want the task to last long and delay the event generation, you could read or write one DBL value.
I attached a VI that I tested and worked. It is based on the DAQmx example VI of finite retrigerrable acquisition, where I add the DAQmx event generation code, with the Event structure inside the While Loop. The LED on the front panel will turn on when the event is generated and off when there is timeout waiting for the event.
The drawbacks of this approach is that you need to use a APFI line as a trigger source, that not all DAQmx devices have, reserve a line for the dummy task, and handle the timeout for the task, if the analog trigger does not arrive at the input.
Does this workaround solve your problem?
Please let me know what you think!
03-23-2011 06:02 PM
Hi PatriciaAD,
many thanks for your help, but unfortunately I can't use your suggestion, because I'm working in pure daqmx c api - I don't use labview. But as I read your comment, your solution is a little bit different from that what I need.
In my system the daq-device continuously watches the selected AI line, and every time when the input signal goes above a specified trigger level, the device executes a callback event. (Meanwhile, on the other AI channels, a continuous daq is running in the foreground.)
This method is built on the above mentioned, very effective "Config_ATrig_Event_Message" function. In this solution there is no need to use trigger source, PFI line and other resources. (All GPCTR and DIO lines are used for other tasks.)
Meantime I found 3 interesting (but poorly documented) function in the ni-daqmx c reference help:
DAQmxGetAnlgWinRefTrigWhen(TaskHandle taskHandle, int32 *data);
DAQmxSetAnlgWinRefTrigWhen(TaskHandle taskHandle, int32 data);
DAQmxResetAnlgWinRefTrigWhen(TaskHandle taskHandle);
This is very promising, but there's no detailed info about it, so I don't know how should I write a triggered callback procedure with the help of these functions. I was looking for relevant info on the NI site, on the net, searching for related docs on the NI's ftp too, but couldn't find anything..
Does anybody know how to use these "top secret" functions?
- George -
03-24-2011 08:26 AM
Hi George,
Thanks for the extra info on your application, it helps understand better what you are looking for. The DAQmx API is basically the same in LabVIEW as it is in C, so I think we can figure out a solution together.
My question now is: Do you need a) an analog hardware trigger to control a DAQmx task or b) to generate a callback event, like if the user pressed a button for example?
Because the functions you mentionned seem to me to configure a analog window reference trigger for a DAQmx task (option a). For option b, if you are constantly measuring the line you want to trigger the event, is there a general purpose callback event generation function in C you could use when you detect the voltage change you are looking for?
Take care,
Patricia
03-24-2011 06:20 PM
Dear Patricia,
A simple callback is sufficient. But in my case this is a very time-critical task: if the trigger-signal appears, callback must be executed immediately. It means, that by the time a daq cycle is complete (i.e. buffer is ready), callback has already been done.
So I can't carry out the change detection by software method since the data acquisition is not ready yet.
I think, this can be performed only by hardware-level daqmx function.
Best,
George
03-29-2011 05:33 AM
Hi George,
I looked through the DAQmx help for C programming. Unfortunately it seems that the function you were using, Config_ATrig_Event_Message, is not available in the current DAQmx set of functions. Therefore you will eventually need a workaround that will most probably mean creating an extra task, whether it is AO, DIO or AI. If you configure the task to be finite acquisition/generation it will take the minimum amount of time. Do you have any available IO lines you are not using on your board?
If you search for "Analog Trigerring Considerations", there is a general description on how analog triggers work for one or multiple tasks, on different devices like E series and M series. You have to use the APFI line, that is not available on all devices.
There were a few functions you mentionned and I will explain more in detail what actions they perform, and how you can use then to create your callback event.
First of all, the DAQmx Register Event registers a function to execute when
samples are transfered into/acquired from the buffer,
a task is done or
when one of the 4 hardware events listed below occurs.
The complete list of hardware events is under the "Events" topic.
Sample clock - defined by the timing source of the task
Sample complete event - occurs when a sample has been acquired from every channel in the task
Change detection event - for digital input lines, when there is a transition from 0 to 1 or 1 to 0
Counter output - when a counter reaches the terminal count
The other functions you were asking about,
DAQmxGetAnlgWinRefTrigWhen
DAQmxSetAnlgWinRefTrigWhen
DAQmxResetAnlgWinRefTrigWhen
control whether the analog window trigger, meaning the trigger for a task that occurs when an analog signals' value is in a specified window, occurs when the signal enters the window or when it leaves the window. This sets the "active slope" of the analog signal.
There are many possible combinations of tasks and hardware signals you can use to generate the callback, depending mostly on your hardware configuration.
Please let me know if you can implement this task!
03-31-2011 03:38 AM
Dear Patricia,
very thanks for your answer. Based on your previous suggestion, I replaced the missing Config_ATrig_Event_Message function with a similar method in the following way:
1. I decreased the daq cycle to a very short (50 ms) time (originally it was 500 ms) - in this way I get small buffer snippets.
2. In this small buffer, I scan for amplitude changes and start callback event if necessary.
3. Then this buffer snippet added to a large buffer (this large buffer represents the original 500 ms long daq-buffer).
4. If the large buffer is full, data processing begins.
In this way I can start event before large buffer is ready, so I have got a method that nearly compatible with the old version.
Thanks for your kindly help!
All the best,
George