Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to route sampleclock to a PFI

Solved!
Go to solution

Hello

Is there an example how in C# to route a sample clock out to a PFI port? The manual stated it is possible but not how. 

I uses two PCIe 6553 cards where i want to shift data in and out with the same clock. This signal needs also clocks an external devices.
The cards are with RTSI connected.

The following code is a first step to try to make it works, it use only the inputs of both cards.
In this sample the tasks start reading with a BeginReadWaveform. Is it possible to start all tasks at the same time?

void SampleAllInputs()
{
List<string> digitalInputAChannels = new List<string>() { "/dev1/port0/line0" };
List<string> digitalInputBChannels = new List<string>() { "/dev1/port0/line0, /dev1/port0/line1" };
List<string> analogInputAChannels = new List<string>() { "/dev1/ai0" };
List<string> analogInputBChannels = new List<string>() { "/dev1/ai0" };

Task digitalInputATask = null;
Task digitalInputBTask = null;
Task analogInputATask = null;
Task analogInputBTask = null;

rate = 1000;
_samplesPerChannel = 1000;
double bufferSize = rate * _samplesPerChannel;

try
{
digitalInputATask = new Task("digitalInputATask");
digitalInputBTask = new Task("digitalInputBTask");
analogInputATask = new Task("analogInputATask");
analogInputBTask = new Task("analogInputBTask");

foreach (var item in digitalInputAChannels)
{
digitalInputATask.DIChannels.CreateChannel(item, "", ChannelLineGrouping.OneChannelForEachLine);
}
foreach (var item in digitalInputBChannels)
{
digitalInputBTask.DIChannels.CreateChannel(item, "", ChannelLineGrouping.OneChannelForEachLine);
}
foreach (var item in analogInputAChannels)
{
analogInputATask.AIChannels.CreateVoltageChannel(item, "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts);
}
foreach (var item in analogInputBChannels)
{
analogInputBTask.AIChannels.CreateVoltageChannel(item, "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts);
}

analogInputATask.Timing.ConfigureSampleClock("", rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, _samplesPerChannel);
analogInputBTask.Timing.ConfigureSampleClock("/dev1/ai/SampleClock", rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, _samplesPerChannel);
digitalInputATask.Timing.ConfigureSampleClock("/dev1/ai/SampleClock", rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, _samplesPerChannel);
digitalInputBTask.Timing.ConfigureSampleClock("/dev1/ai/SampleClock", rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, _samplesPerChannel);

analogInputATask.Control(TaskAction.Verify);
analogInputBTask.Control(TaskAction.Verify);
digitalInputATask.Control(TaskAction.Verify);
digitalInputBTask.Control(TaskAction.Verify);

AnalogMultiChannelReader analogMultiChannelReaderA = new AnalogMultiChannelReader(analogInputATask.Stream);
AnalogMultiChannelReader analogMultiChannelReaderB = new AnalogMultiChannelReader(analogInputBTask.Stream);
DigitalMultiChannelReader digitalMultiChannelReaderA = new DigitalMultiChannelReader(digitalInputATask.Stream);
DigitalMultiChannelReader digitalMultiChannelReaderB = new DigitalMultiChannelReader(digitalInputBTask.Stream);

AsyncCallback analogSamplingCallbackA = new AsyncCallback(OnAnalogSampling);
AsyncCallback analogSamplingCallbackB = new AsyncCallback(OnAnalogSampling);
AsyncCallback digitalSamplingCallbackA = new AsyncCallback(OnDigitalSampling);
AsyncCallback digitalSamplingCallbackB = new AsyncCallback(OnDigitalSampling);

analogMultiChannelReaderA.SynchronizeCallbacks = true;
analogMultiChannelReaderB.SynchronizeCallbacks = true;
digitalMultiChannelReaderA.SynchronizeCallbacks = true;
digitalMultiChannelReaderB.SynchronizeCallbacks = true;

analogMultiChannelReaderA.BeginReadWaveform(_samplesPerChannel, OnAnalogSampling, analogInputATask);
analogMultiChannelReaderB.BeginReadWaveform(_samplesPerChannel, OnAnalogSampling, analogInputBTask);
digitalMultiChannelReaderA.BeginReadWaveform(_samplesPerChannel, OnDigitalSampling, digitalInputATask);
digitalMultiChannelReaderB.BeginReadWaveform(_samplesPerChannel, OnDigitalSampling, digitalInputBTask);
}
catch (DaqException exception)
{
if (digitalInputATask != null) { digitalInputATask.Dispose(); }
if (digitalInputBTask != null) { digitalInputBTask.Dispose(); }
if (analogInputATask != null) { analogInputATask.Dispose(); }
if (analogInputBTask != null) { analogInputBTask.Dispose(); }
}
}

void OnAnalogSampling(IAsyncResult ar)
{
var task = ar.AsyncState as Task;
if (task == null) { return; }
try
{
AnalogMultiChannelReader reader = new AnalogMultiChannelReader(task.Stream);
AnalogWaveform<double>[] data = reader.EndReadWaveform(ar);
...
reader.BeginReadWaveform(_samplesPerChannel, callBack, task);
}
catch (DaqException daqException)
{
task.Dispose();
task = null;
}
}

void OnDigitalSampling(IAsyncResult ar)
{
var task = ar.AsyncState as Task;
if (task == null) { return; }

try
{
DigitalMultiChannelReader reader = new DigitalMultiChannelReader(task.Stream);
DigitalWaveform[] data = reader.EndReadWaveform(ar);
...
reader.BeginReadWaveform(_samplesPerChannel, OnDigitalSamplingA, task);
}
catch (DaqException daqException)
{
task.Dispose();
task = null;
}
}

0 Kudos
Message 1 of 3
(2,374 Views)
Solution
Accepted by topic author Leonderthaler

Hi,

 

Unfortunately I cannot program in C# however I have found the following that may be useful to you:

 

https://forums.ni.com/t5/Counter-Timer/Route-Sample-Clock-Through-External-PFI/td-p/3275871

 

http://www.ni.com/tutorial/2740/en/

 

I hope these are of use to you,

 

Amy

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

Hi Amy,

Thank for your post. It helps me a lot.

 

Regards

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