Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if reference trigger stopped acquisition? IsDone always false.

Hi, I have a problem in a setup using both the start trigger and reference trigger to start and stop the data acquisition using a hardware signal. Basically my setup is working in that my signal is sampled from the start trigger until the reference trigger, however I now only know that because after the reference trigger no more samples are available. I would like to check if the reference trigger has occurred to close my acquisition screen, and I thought I could do that using the IsDone property of the task. However, IsDone is always false.

 

 

My source looks like this:

 

myTask.AIChannels.CreateVoltageChannel(channelName, "", AITerminalConfiguration.Rse, -5, 5, AIVoltageUnits.Volts);
myTask.Timing.ConfigureSampleClock("", config.SampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChannel);
var srcTriggerLine = $"/{mxDevice.DeviceID}/PFI0";
myTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(srcTriggerLine, DigitalEdgeStartTriggerEdge.Rising);
myTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger(srcTriggerLine, DigitalEdgeReferenceTriggerEdge.Falling, samplesPerChannel);

myTask.Stream.ReadRelativeTo = ReadRelativeTo.CurrentReadPosition;
myTask.Stream.ReadOverwriteMode = ReadOverwriteMode.DoNotOverwriteUnreadSamples;


_reader = new AnalogUnscaledReader(myTask.Stream);
_reader.SynchronizeCallbacks = false;

myTask.Start();
while (!(myTask.IsDone && samplesAvailable == 0)) {
    samplesAvailable = (int)myTask.Stream.AvailableSamplesPerChannel;
    _data = _reader.ReadInt16(samplesAvailable);
}

First I used the asynchronous method for data acquisition and got a time out exception (as expected), but I changed it to this because I thought I would be better able to handle the stop trigger. Using the asynchronous method I also didn't get an IsDone event. The device I am using is the USB-6211.

 

I could use the time out exception using asynchronous method, or check if availableSamples becomes zero but it I would prefer some way of directly checking if the reference trigger stopped the acquisition since there might be other reasons for samples to be collected (ie an acquisition problem).

0 Kudos
Message 1 of 7
(3,907 Views)

Hi Eldering, 

 

Have you manged to get a solution to this? 

I'm definitely not an expert in any text based languages but there should be referenced information that downloads with LabVIEW, what language is the below source and what environment are you trying to write this in?  

 

A useful tutorial I found isn't very specific but may be a good starting point: 

Using DAQmx in text based programming environments: https://www.ni.com/en/support/documentation/supplemental/21/using-ni-daqmx-in-text-based-programming...

 

There should also be help references for different languages and DAQmx functions, please see following link:

http://digital.ni.com/public.nsf/allkb/6C3024A6628FB629862575CC0079206A 

 

I hope these are useful

 

Courtney

0 Kudos
Message 2 of 7
(3,835 Views)

Thanks for the reply Courtney, unfortunatelly it didn't get me closer to a solution to my problem. I am fairly familiar with the programming interfaces in both C# as Labview, but I don't know why the task is not marked done after the reference trigger.

0 Kudos
Message 3 of 7
(3,815 Views)

Hi Eldering,

 

Have a look at the following examples and let me know if this is what you are looking for:

 

https://forums.ni.com/t5/Example-Programs/Acquisition-Stop-Trigger-Using-LabVIEW-with-DAQmx/ta-p/350...

https://forums.ni.com/t5/Example-Code/Archived-NI-DAQmx-Continuous-Analog-Input-with-Both-Start-and/...

 

Regards,

Roberto

National Instruments AE

0 Kudos
Message 4 of 7
(3,807 Views)

Hi Roberto,

 

Thanks for your reply. I've been on holiday so I couldn't respond sooner. The second example you've linked is what I've based my own code on. That example however also checks the IsDone flag to stop the acquisition loop, but as I described that flag is never set in my case. I will try to use the example code as-is with my hardware, to see if that does work correctly.

 

The first example simple checks for an error and for me this poses two problems:

1) I think this will not acquire all data up to the reference trigger, since during the last read the buffer will be partially filled. Because the buffer is not entirely filled a time-out error will occur, but then the data that is in the buffer will not be acquired. It might be possible to still read that data after the error, but it is not shown in the example. If data is missed then it will not only cause the loss of that data but it will also affect the time synchronisation of the entire recording, so it is important to capture exactly the right amount of data.

2) I will not know whether the acquisition stopped due to the reference trigger or if there was another reason that caused the acquisition to stop (for example some kind of real error). It generates a time-out exception, but I can imagine that the time-out exception is also thrown in other situations than after a reference trigger. This is important for us because if the data stops due to a reference trigger we can adjust the time synchronisation, but if it stopped for another reason then adjusting the synchronisation would corrupt our data.

 

0 Kudos
Message 5 of 7
(3,736 Views)

Roberto, I have noticed both examples that you've referenced use the FiniteSamples mode while I'm using ContinuousSamples. Does the IsDone flag not get set when in continuous mode after receiving the reference trigger? If so how can I check if the reference trigger occured?

0 Kudos
Message 6 of 7
(3,728 Views)

Ignore my previous remark, I was looking at an older version of my code without the synchronisation. The code I'm using now uses FiniteSamples as well (as shown in my first post in this thread).

0 Kudos
Message 7 of 7
(3,723 Views)