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.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Starting a ReadWaveform on an external trigger?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 7
(4,455 Views)

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:

 

  • Which DAQ card are you using? (not all cards support hardware triggering, so this may affect how your task executes)
  • Are you making sure that the PFI trigger you're using isn't already high when the task starts?
  • How does your task behave if you comment out the triggering code?

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

0 Kudos
Message 2 of 7
(4,439 Views)

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.

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

Hi CurtisHx,

 

I would recommend following this example with your hardware to rule out software as an error source.

0 Kudos
Message 4 of 7
(4,418 Views)

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?

0 Kudos
Message 5 of 7
(4,371 Views)
Solution
Accepted by CurtisHx

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.

Message 6 of 7
(4,349 Views)

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.

0 Kudos
Message 7 of 7
(4,344 Views)