Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger Restart example

I want to setup a task with AIChannels, timing, and a digital edge start trigger. I start the task, and the board (PXI-6123) receives the first trigger. It aquires finite samples and then waits for next trigger.
 
I found the Labview example Acq&Graph Voltage-Int Clk-HW Trig Restarts.vi has the function I am looking for. But I can not find such a C# example.
 
Does anybody know is there such an example available? Or can anybody translate the Labview example into C# example?
 
Thanks a lot.
0 Kudos
Message 1 of 15
(4,115 Views)

Hello JSInc,

This LabVIEW example begins by creating an analog input voltage task, setting up a sample clock with finite samples. After configuring a sample clock for finite sample, it configures an analog trigger by setting source to look at, what level to trigger at, and whether the analog signal’s slope should be rising or falling. This can be done in C with DAQmxCfgAnlgEdgeStartTrig().  

After the trigger is configured, you then “commit the task” with the function DAQmxTaskControl(). If your application performs multiple measurements or generations by repeatedly starting and stopping a task, explicitly committing the task exclusively acquires the resources that the task uses and programs some of the settings for these resources. By explicitly committing the task, these operations are performed once, not each time the task is started, which can considerably decrease the time needed to start your task.

You then begin a while loop, where each loop starts the task, reads the finite samples, then stops the task. After you close the while loop, you clear the task to release it.

I hope this explanation helps,

Mallori M.

Mallori M
National Instruments
Sr Product Manager, Customer Proficiency

ni.com/training
0 Kudos
Message 2 of 15
(4,098 Views)
Hello Mallori,


Thank you for your reply. Can this be done in C#?


JSInc
0 Kudos
Message 3 of 15
(4,096 Views)

Hi JSInc,

Yes this can be done in C# using callbacks instead of while loops. I would look at modifying the ContAcqVoltageSamples_IntClkAnalogStart example program because this example would have the callbacks already set up. There are a few adjustmentst that you can make to the code to recreate the LabVIEW example you previously found.

The first change would be to make the task type FiniteSamples when configuring the sample clock Timing specs. You will also need to make sure that the Samples /Channel input on the form is what is used for the number of samples to read when configuring the sample clock.

The next change to make is in the code, after you configure the task, there is a function that verifies the task. You can copy and paste to repeat this task, but change Verify to Commit, so that the task is commited as I stated inmy previous post.

The last edit you will need to make is, in the AnalogInCallback, you will want to add a myTask.start (); after the myTask.stop(); This is what creates the element of retriggerability. When we first start the task it waits until the analog trigger to acquire a finite amount of samples, display the sample, stop the task, and then start the task again so that it is waiting for the next analog trigger.

I hope this explanation helps,

Mallori M.

Mallori M
National Instruments
Sr Product Manager, Customer Proficiency

ni.com/training
0 Kudos
Message 4 of 15
(4,081 Views)
Mallori,
 
Thank you for your very detail explaination. I will try to modify the example.
 
 
JSInc
0 Kudos
Message 5 of 15
(4,004 Views)
Hello Mallori,
 
I can not get the last edit done, since there is not myTask.stop();  in the AnalogInCallback or anywhere else. Could you please double check?
 
Thanks,
 
 
JSInc.
0 Kudos
Message 6 of 15
(3,989 Views)

Hello Mallori,

It seems like if I do not do the last edit, the code is already functioning as expected as the Labview example. Any comment?

 

Thanks,

 

JSInc

 

0 Kudos
Message 7 of 15
(3,977 Views)

Hi JSInc,

Sorry about that, you might need to add the stop task to the callback as seen in the attached image. If you are expecting to only trigger once each time you hit the start button, then it should work fine without the stop and start tasks. However, if you want the retriggerability, where you only push the start button once but each time a rising edge is seen a finite number of samples is taken, then I believe that you will need the stop and start tasks. However, if the program is working to your satisfaction, then you can just keep this in mind in case you need to change the behavior later down the road.

Regards, Mallori M.

Mallori M
National Instruments
Sr Product Manager, Customer Proficiency

ni.com/training
0 Kudos
Message 8 of 15
(3,942 Views)
Hello Mallori,

Thank you for your reply.

I have another question:

I am using digital edge start trigger, and I want to set the start delay by

                    //Configure Trigger Start Delay
                    DelayUnits = StartTriggerDelayUnits.Seconds;
                    myTask.Triggers.StartTrigger.Delay = Convert.ToDouble(StartDelayInSeconds);

It seems in C# the minimum valid start delay is 2 seconds. However in Labview the start delay could be a few milliseconds. My timing configuration is

myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(samplingRate), SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numberOfSamplesToRead);

How can I achieve millisecond level start delay in C#?


Best regards,

JSInc

0 Kudos
Message 9 of 15
(3,938 Views)

Hello JSInc,

To accomplish a millisecond level start delay in C#, you should change the StartTriggerDelayUnits to either SampleClockPeriods or Ticks. Suppose I was using a 1MHz sample clock, and I wanted to have a start trigger delay of 1 millisecond.  The code to configure my start trigger delay might look something like this:

//Configure Start Trigger Delay

DelayUnits = StartTriggerDelayUnits.SampleClockPeriods;

myTask.Triggers.StartTrigger.Delay = Convert.ToDouble(1000);

The number of sample clock periods should be the number of millisecond delay you want times 1000 for a 1MHz sample clock.

Best wishes,

Wallace F.

National Instruments
Applications Engineer
0 Kudos
Message 10 of 15
(3,909 Views)