Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change DI to non-buffered mode

Solved!
Go to solution

My application is when a (camera ready) digital input falling edge happens, it will trigger a pulse from counter 0, to initiate the camer shutter.

The following code does that:

 

camShutterOutputTask.COChannels.CreatePulseChannelTime("Dev1/ctr0", "",
COPulseTimeUnits.Seconds, COPulseIdleState.Low,
0,
0.000001,
((double)exposure_time) / 1e6);

camShutterOutputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger("/Dev1/PFI0", DigitalEdgeStartTriggerEdge.Falling); camShutterOutputTask.Triggers.StartTrigger.Retriggerable = true;

 

On my PCIe-6323, PFI0 is by default configured with P1.0, so I physically connected the camera ready input to P1.0.

 

I only want to trigger the camera a number of times. After the required number of triggers, I will just ignore any following input signals. Here is code that configure the input channel to do that:

 

camReadyInputTask.DIChannels.CreateChannel("Dev1/port1/line0", "", ChannelLineGrouping.OneChannelForEachLine);
camReadyInputTask.Timing.ConfigureChangeDetection( "", "Dev1/port1/line0", SampleQuantityMode.FiniteSamples, num_of_frames);

The problem is when I run the program, I got the error: "Selected lines do not support buffered operations. Ensure only lines that support buffered operations are being used in the task. if using change detection timing, the task must be changed to non-buffered to support these lines."

 

But if I use port 0 in the code instead of port 1, it gets pass the error, and it limits the number of input signals just like what I need. However port 0 does not connect to any PFI so I cannot use it in the start trigger for camera shutter anymore.

 

Does anybody know how to either:

1. Change a task to non-buffered mode or 

2. Re-route port 0 to a PFI?

 

 

0 Kudos
Message 1 of 3
(4,239 Views)

 

Unfortunately there doesn't seem to be a way to route Port 0 to the PFI lines, and the task is buffered because of the timing configuration setup.  However, a possible workaround could be to manually retrigger the counter output pulse task with a for loop.  In psuedocode, this would look like:

 

for (n=0:num_of_frames)

{

    start task;

    while (myTask.isDone = F)

          {

                wait 5 ms;

          }

    stop task;

}

clear task;

 

Hope this helps!

 

Ashley G.

 

Ashley G.
Principal Applications Engineer | RF & Wireless Communications
0 Kudos
Message 2 of 3
(4,188 Views)
Solution
Accepted by topic author joehsiao

Thanks for the reply Ashly. I am new to DAQmx and there is still a lot to learn.

 

The loop trick involves software timed waits and that concerns me.

I found a workaround that invokes a callback function every time the counter changes its output:

 

 

camShutterOutputTask.SynchronizeCallbacks = true;
camShutterOutputTask.CounterOutput += new CounterOutputEventHandler(camShutter_callback);

...

private void camShutter_callback(object sender, CounterOutputEventArgs e)
{
trigger_count++;
Console.WriteLine("Trigger count = " + trigger_count.ToString());
if (trigger_count >= num_of_frames * 2)
{
try
{
camShutterOutputTask.Stop();
camShutterOutputTask.Dispose();

...

startCaptureButton.Enabled = true;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}

 

 

In camShutter_callback(), I keep track a global counter and if it is greater than num_of_frames*2 (since the callback will be triggered on both rising and falling edge of one pulse), I stop all the tasks. 

0 Kudos
Message 3 of 3
(4,173 Views)