Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble reading a single sample from multiple lines inside DigitalChangeDetection event handler

Solved!
Go to solution

Hello friends,

 

I am interfacing with a NI cDaq-9174 and a NI 9401 DIO module. I am trying to create a single task that detects rising edge changes on 2 digital inputs and runs some functions depending on what channel the change was detected on. The code that configures my task is shown below.

 

_task?.Dispose();
_task = new Task("InputTask");
_task.DIChannels.CreateChannel(_hardwareInfo.SecondDigitalIoModuleName + "/port0/line0", "di0",
    ChannelLineGrouping.OneChannelForEachLine);
_task.DIChannels.CreateChannel(_hardwareInfo.SecondDigitalIoModuleName + "/port0/line1", "di1",
    ChannelLineGrouping.OneChannelForEachLine);
_task.Timing.ConfigureChangeDetection(_hardwareInfo.SecondDigitalIoModuleName + "/port0/line0:1", "", 
    SampleQuantityMode.ContinuousSamples);
_task.DigitalChangeDetection += async (sender, args) =>
{
    bool[,] data = _reader.ReadSingleSampleMultiLine();

    if (data[1, 0])
    {
        await _outputPreparationMediator.PrepareOutputAsync();
    }

    if (data[0, 0])
    {
        _outputMediator.StartOutputTasks();
    }
};
_task.Control(TaskAction.Verify);
_task.Control(TaskAction.Reserve);
_reader = new DigitalMultiChannelReader(_task.Stream);

When the DigitalChangeDetection event handler is executed, calling ReadSingleSampleMultiLine() causes the following exception to get thrown.

 

 

NationalInstruments.DAQmx.DaqException
  HResult=0x80131501
  Message=Digital input detected a new sample clock before the previous sample was latched into onboard memory.

If you are using an external sample clock, ensure that it is connected, within the jitter and voltage level specifications, and without glitches. If applicable, reduce your sample clock rate or use a product capable of higher sample clock rates.

Task Name: InputTask

Status Code: -200715
  Source=NationalInstruments.DAQmx

It is not clear to me how to fix this issue. I am not using an external sample clock and it is not applicable for me to reduce my sample clock rate (I never configure the tasks clock explicitly).

 

Any idea what might be happening here?

 

0 Kudos
Message 1 of 3
(2,049 Views)

Hi b!tmaster,

 

If you don't explicitly set a sample clock rate it'll sit at 1 kHz. Try adjusting that with the SampleClockRate property to see if either lowering it or increasing it does anything for you. 

 

BDog

0 Kudos
Message 2 of 3
(2,011 Views)
Solution
Accepted by topic author b!tmaster

Hi,

 

Just wanted to post an update and say that the issue I was experiencing was not due to faulty code but actually due to a wiring issue.

 

Thanks!

0 Kudos
Message 3 of 3
(2,006 Views)