From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-03-2016 08:59 AM
I have a DigitalMultiChannelReader that I need to start reading a waveform when an external line changes. For example, I want to read Port3 lines 3 and 4 when PFI5 goes high, for a certain number of samples.
readWaveformTask = new NationalInstruments.DAQmx.Task(); readWaveformTask.DIChannels.CreateChannel("PXI1Slot6/Port3/Line3, PXI1Slot6/Port3/Line4", "", ChannelLineGrouping.OneChannelForEachLine); readWaveformTask.Timing.ConfigureSampleClock( "", samplesPerSecond, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesToCollect); readWaveformTask.Stream.Timeout = 1000; readWaveformTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("PXI1Slot6/PFI5", DigitalEdgeStartTriggerEdge.Rising); DigitalMultiChannelReader reader = new DigitalMultiChannelReader(readWaveformTask.Stream); //TODO: How do I make the reader not start the task here? reader.ReadWaveform(samplesToCollect);
The code above will start the task and start reading the waveform as soon as "reader.ReadWaveform(samplesToCollect)" is called.
How can I trigger a waveform aquisition using an external trigger?
Solved! Go to Solution.
02-04-2016 02:41 PM
Hi CurtisHx,
At first glance it seems like you're setting up your external triggering correctly in software. I have a few followup questions, though:
I would also recommend going through the SyncAIAOUsingDigTrigger Example in the DAQmx cs Example files, which can be found in your directory at Documents\National Instruments\Measurement Studio\DotNET\Examples\DAQmxWithUI\SynchronizeAIAOUsingDigTrigger\cs.
02-04-2016 02:58 PM
The DAQ card is the PXIe-6535.
I can clearly see the PFI trigger line go high on my scope, and I have driven (and confirmed) that PFI line before. The PFI trigger line is definitely going high.
The code behaves the same way because reader.ReadWaveform(samplesToCollect) is a synchronous call. I had forgotten there is a BeginReadWaveform method that might do what I want. However, I'm currently having problems with a NI dll BSODing my computer that I need figure out first.
02-05-2016 03:18 PM - edited 02-05-2016 03:18 PM
Hi CurtisHx,
I would recommend following this example with your hardware to rule out software as an error source.
02-08-2016 10:30 AM - edited 02-08-2016 10:34 AM
Alright. I have absolutely no idea why this code is not working. I want to trigger the start of a waveform aquisition when PFI5 goes high. According to the "Device Routes" tab for the PXIe-6535 in NI MAX, PFI5 is directly connected to PXI_Trig0, so I should not have to manually configure that route. The actual waveform aquisition sample clock should be the PXIe-6535 internal timing engine. I just want to start aquisition on an external trigger. I think I followed the instructions here correctly.
However, this code throws a "failed to get all of the samples" excpetion when I end reading the waveform. How is it that the callback is being called before all of the samples are being aquired?
Code:
ManualResetEventSlim resetMe = new ManualResetEventSlim(); using (NationalInstruments.DAQmx.Task task = new NationalInstruments.DAQmx.Task("Trigger Me")) { task.DIChannels.CreateChannel("PXI1Slot6/Port3/Line3", "Vibrator Line", ChannelLineGrouping.OneChannelForAllLines); task.Timing.ConfigureSampleClock("", 2000000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 2000000); task.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("PXI_Trig0", DigitalEdgeStartTriggerEdge.Rising); DigitalSingleChannelReader reader = new DigitalSingleChannelReader(task.Stream); DigitalWaveform outputWaveform; task.Control(TaskAction.Verify); task.Start(); reader.BeginReadWaveform(2000000, (result) => {
//This line throws the DAQmx exception below. outputWaveform = reader.EndReadWaveform(result); resetMe.Set(); }, null); resetMe.Wait(); }
Exception:
NationalInstruments.DAQmx.DaqException was unhandled by user code Error=-200284 HResult=-2146233087 Message=Some or all of the samples requested have not yet been acquired. To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock. Property: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo Requested Value: NationalInstruments.DAQmx.ReadRelativeTo.FirstSample Property: NationalInstruments.DAQmx.DaqStream.ReadOffset Requested Value: 0 Task Name: Trigger Me Status Code: -200284 InnerException:
At the end of the day, I want to measure the frequency and duty cycle of a PWM signal. Is there a better way of doing this?
02-09-2016 11:21 AM
CurtisHx,
Actually, even if the Device Routes shows a direct connection between your PFI line and the trigger line in MAX, that only means that there is a possible connection between those lines. You will still need to manually connect those terminals, which can be done easily with the DAQmx Connect Terminals method. If you need a more in-depth explanation of the method, you can find it here.
02-09-2016 11:50 AM
Gotchya. I thought I was missing a step in there somewhere. MAX was just indicating what could connect to what. The actual connection still has to specified in software. That makes more sense.