02-26-2016 07:15 AM
I'm trying to block program excecution until PXI1Slot6/Port1/Line1 goes high, but the Task.DigitalChangeDetection event never fires.
ManualResetEventSlim waitForTrigger = new ManualResetEventSlim();
        using (Task task = new Task())
        {
          task.DIChannels.CreateChannel("PXI1Slot6/Port1/Line1", "", ChannelLineGrouping.OneChannelForAllLines);
          task.Start();
          task.DigitalChangeDetection += (e, o) =>
           {
             waitForTrigger.Set();
           };
          waitForTrigger.Wait();
        }I can clearly see Port1/Line1 going high and low on the scope, but the DigitalChangeDetection event never fires. According to the documentation on the DigitalChangeEvent :
Occurs when a digital change is detected on any of the digital lines used in the task.
So why doesn't Port1/Line1 going high low fire the DigitalChangeDetection event?
02-29-2016 10:29 AM
Problem 1: Change detection must be explicitly configured using NationalInstruments.DAQmx.Task.Timing.ConfigureChangeDetection
Problem 2: The DigitalChangeDetection even handler must be regisered BEFORE calling Task.Start();
This code triggers correctly:
        ManualResetEventSlim waitForTrigger = new ManualResetEventSlim();
        using (Task task = new Task())
        {
          task.DIChannels.CreateChannel("PXI1Slot6/Port0/Line0", "", ChannelLineGrouping.OneChannelForAllLines);
          task.Timing.ConfigureChangeDetection("PXI1Slot6/Port0/Line0", "", SampleQuantityMode.ContinuousSamples);
          task.Stream.Timeout = millisecondsToWait;
          task.DigitalChangeDetection += (e, o) =>
          {
            waitForTrigger.Set();
          };
          task.Start();
          
          if (!waitForTrigger.Wait(millisecondsToWait))
            throw new TimeoutException(
              String.Format("Failed to trigger on {0} in {1}ms", trigger, millisecondsToWait)
              );
        }