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,
It seems like if I do not do the last edit, the code is already functioning as expected as the Labview example. Any comment?
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.
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.