How can I set up a digital input task to read continuous samples?

I am trying to create an exclusively digital task that will make digital readings at a rate timed by the material using a PCIe-6509. However, when I try to put the task timing as follows (which works on a PCIe-6509), I get the following error:

Requested value is not supported for this property value. The value of the property may be invalid because it is in conflict with another property.

Property: NationalInstruments.DAQmx.Timing.SampleTimingType

Required value: NationalInstruments.DAQmx.SampleTimingType.SampleClock

Possible values: NationalInstruments.DAQmx.SampleTimingType.OnDemand, NationalInstruments.DAQmx.SampleTimingType.ChangeDetection

Task name: DigitalInputTask

State code:-200077

The relevant parts of my code are:

    public class DigitalInputReader: IDisposable
{
public DigitalInputReader()
{
dataReadyHandler = new System.AsyncCallback (DataReadyEventHandler);

daqmxTask = new DigitalInputTask();
daqmxTask.Configure (Globals.NI);

daqmxTask.Control (TaskAction.Verify);
daqmxTask.Control (TaskAction.Commit);

daqmxReader = new DigitalMultiChannelReader (daqmxTask.Stream);
}

public class DigitalInputTask: task
{

public DigitalInputTask(): {base ("DigitalInputTask")}

public virtual void Configure (NiConfiguration niConfig)
{
<= niconfig.digitalinputs.count="" -="" 1;="">
{
String physicalChannelName = niConfig.Device + "/ port" + niConfig.DigitalInputs [i]. Port.ToString () + "/ line" + niConfig.DigitalInputs [i]. Channel.ToString ();
String nameToAssignToChannel = niConfig.DigitalInputs [i]. Name;

DIChannel ch is this. DIChannels.CreateChannel (physicalChannelName, nameToAssignToChannel, ChannelLineGrouping.OneChannelForEachLine);
c. InvertLines = niConfig.DigitalInputs [i]. InvertLines;
}
var signalSource = "";
This. Timing.ConfigureSampleClock (signalSource, Globals.MachineSettings.SampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);// Globals.MachineSettings.SamplesPerChannel);
}
}

The last call to Task.Timing.ConfigureSampleClock, it's which throw errors.

Of the options available, or SampleTimingType.OnDemand or NationalInstruments.DAQmx.SampleTimingType.ChangeDetection provide the same precisely timed calls that I am familiar with the analog input interruptions.

How is it possible in a digital task?  I mean, it seems that I could set up another task to do call by material for the production of a clock signal and use the ChangeDetection synchronization mode, but this seems a bit complicated for what should be easy to do.  What Miss me?

Update: I thought about it.  You cannot call ConfigureSampleClock when the digital input card is a device of 650 x, because these devices have any automated examples of clock.  They are configured to run in mode default finite samples.  You must make all sample synchronizing with these devices in the software.

Be cautious, however, because the .NET timers ensure they put any faster than their scheduled interval.  In practice, they are usually 5 to 10 ms slow by tick.  This means that if you want to read samples every 100 ms by sample clock, you'd end up reading all 108 ms samples.  All counters based on the elapsed time and number of samples would be away after a few seconds of it.

Instead, you must do one of four things: write a doggone driver that runs in ring 0 and interfaces with the PCIe card in the required interval (i.e. on NC, not you, in practice), tolerate the inclination of the clock, use a multimedia timer as an interruption audio or video that is more likely to respond to the correct interval, or , my solution, an accurate clock allows you to set the interval of the timer.  I wrote the following code to the timer:

var CorrectiveStopwatch = new System.Diagnostics.Stopwatch();
var CorrectedTimer = new System.Timers.Timer()
{

Interval = targetInterval,
AutoReset = true,
};
CorrectedTimer.Elapsed += (o, e) =>
{
var actualMilliseconds =;

Adjust the next tick so that it's accurate
EG: Stopwatch says we're at 2015 ms, we should be at 2000 ms
2000 + 100 - 2015 = 85 and should trigger at the right time
var StopwatchCorrectedElapsedMilliseconds = newInterval +.
targetInterval-
CorrectiveStopwatch.ElapsedMilliseconds;

If we're over 1 target interval too slow, trigger ASAP!
<=>
{
NvelIntervalle = 1;
}

CorrectedTimer.Interval = NvelIntervalle;

StopwatchCorrectedElapsedMilliseconds += targetInterval;
};

I hope this helps someone.

Tags: NI Software

Similar Questions

Maybe you are looking for