11-19-2009 12:57 AM
Hello,
I have been tackling this issue on and off for a while, so I thought I'd finally get around to asking what you guys think is the best solution.
I have 3 or 4 different measurement devices (flow meters, motors, etc) that I need to take a measurement at the same time as taking a set of samples from my PCI NI DAQ card.
I understand that they arent going to be totally simultanous, but close enough is good enough.
I am using C#, and what I really want is the ability to take 1 sample, right now... e.g. when I make a call (like I'd expect of ReadSingleSample), I want the very latest sample that was taken for all my channels.
I have the timing set up like this:
AcqTask.Timing.ConfigureSampleClock("", 100, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
Then when I'm in my aquisition loop, I do something similar to:
while(Sampling == true) { AnalogIn.ReadSingleSample(); // Analog in is my AnalogMultiChannelReader for the task. ReadFlowMeter(); ReadMotors(); ReadEtcEtc(); }
In this scenario, it seems that ReadSingleSample just reads the next sample in the buffer, not the last reading taken.
So to get the latest sample, I have to read all the values in the buffer until the last sample.
My other option is to set up the event with appropriate timing, and then just grab out the last value in the array of N samples that it gives back as the "latest".
I dont like this idea, I really want something that goes and takes a sample when I make the call. I understand there will be overhead involved, and I wont be able to get super fast sample rates... but that isnt what I'm after.
If I can do all my samples sequentially, I can actually predictably know when the samples were taken from the various devices.
So... is there a way to take a sample immediately at a function call, or a better way of syncronising non-NI measurement tasks to an NI acquisition?
Thanks 🙂
11-19-2009 10:05 AM
Hello Fuzz,
You can also look in to using the DAQmx Read property "Relative To". This allows you to set the read position to a variety of locations, including the most recent sample. For more information on this, check our the NI-DAQmx help which should be installed to Program Files » National Instruments » NI-DAQ.
Regards,
11-22-2009 06:36 PM
Thanks Seth.
I've been reaing about that property. That makes sense.
Do you have an idea where it might be in the .NET interface? I'm having trouble finding it...
11-22-2009 07:04 PM
Scratch that... I have found it 🙂
It works like this:
string taskName = "MyTask"; Task AcqTask = DaqSystem.Local.LoadTask(taskName); AcqTask.Stream.ReadRelativeTo = ReadRelativeTo.MostRecentSample;