11-28-2009 01:09 PM - edited 11-28-2009 01:11 PM
Hi
I have setup a continuous multichannel analog reader using a callback to signal when the samples have been acquired, using AnalogMultiChannelReader, based on one of the examples supplied. This works fine. I have also setup a similar digital reader DigitalMultiChannelReader and want to read this in the analog callback function, so that I can merge the bits in the space reserved in the buffer with the analog data. But I need to call digitalReader.EndReadWaveform(ar) but ar is the IAsyncResult in the callback argument, so this won't work. Just calling the digitalReader.ReadWaveform(.....) doesn't work without the preceding EndReadWaveform call.
Can't just see how to do this - anybody able to set me straight
Ray
11-29-2009 05:09 AM
Have found a solution.Initialisation is as follows:
analogTask = new Task();
analogTask.AIChannels.CreateVoltageChannel("Dev1/ai0:15", "",
(AITerminalConfiguration)(-1), -10, 10, AIVoltageUnits.Volts);
analogTask.Timing.ConfigureSampleClock("", scanRate, SampleClockActiveEdge.Rising,
SampleQuantityMode.ContinuousSamples, samplesPerChan);
analogTask.Control(TaskAction.Verify);
analogInReader = new AnalogMultiChannelReader(analogTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback);
analogTask.AIChannels.All.DataTransferMechanism = AIDataTransferMechanism.Dma;
analogInReader.SynchronizeCallbacks = true;
analogInReader.BeginReadWaveform(samplesPerChan,analogCallback, analogTask);
runningTask = analogTask;
digitalTask = new Task();
digitalTask.DIChannels.CreateChannel("Dev1/port0", "port0",
ChannelLineGrouping.OneChannelForAllLines);
digitalTask.Timing.ConfigureSampleClock("ai/SampleClock", scanRate,
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);
digitalTask.Control(TaskAction.Verify);
digitalInReader = new DigitalSingleChannelReader(digitalTask.Stream);
digitalTask.DIChannels.All.DataTransferMechanism = DIDataTransferMechanism.Dma;
digitalTask.Stream.ConfigureInputBuffer(samplesPerChan);
digitalTask.Stream.Timeout = -1;
digitalInReader.ReadMultiSamplePortUInt32(-1);
Then in the callback
totAvailableDig = digitalTask.Stream.AvailableSamplesPerChannel;
ddata = digitalInReader.ReadMultiSamplePortUInt32((int)totAvailableDig);
data = analogInReader.EndReadWaveform(ar);
analogInReader.BeginMemoryOptimizedReadWaveform(samplesPerChan,analogCallback,
analogTask, data);
chanCount = 0;
foreach (AnalogWaveform<double> waveform in data)
{
for (int sample = 0; sample < waveform.Samples.Count; sample++)
{
val = waveform.Samples[sample].Value;
buf1[chanCount, sample] = (ushort)(val * offset / 10.0+offset);
dval = (uint)(ddata.GetValue(sample));
}
chanCount++;
}
Do I really need
digitalTask.DIChannels.All.DataTransferMechanism = DIDataTransferMechanism.Dma;
analogInReader.SynchronizeCallbacks = true;
digitalTask.Stream.Timeout = -1;
Ray
12-03-2009 03:28 AM
Hi Ray,
Have you tried running the code with those extra lines included? Does it perform how you wanted it to? From what I can see, the last line, digitalTask.Stream.Timeout = -1;, will set the timeout of the digital task to infinite i.e. you will not receive an error message if the digital signal is not detected. My .net programming is a bit rusty so I am not sure on the other functions. Try running the code with and without those extra lines and see what happens. Let me know if you have any other problems with it.
Kind Regards,
Jas.W
12-03-2009 03:44 AM
Thanks Jason.
If I change the AIDataTransferMechanism.Dma function to the alternative AIDataTransferMechanism.Interrupt then the program can crash sometimes.
But what is the default setting, if it is Dma then I can leave that line out. Incidentally where do I find the default settings documented?
I have found that leaving the other two lines out seems to make no difference, but again I would like to know what the defaults are
Regards
Ray
12-03-2009 05:50 AM
Hi Ray,
I've had a look to see if I can find what the default values are and the only function I could find a default value for was the SynchronizeCallbacks, which by default is set to true. In the past, if I've not specified the timeout it would wait for around 10 seconds before producing an error. As for the AIDataTransferMechanism function, again I couldn't find what the default function is so it may be best to keep that as DMA.
If you have any further questions then please let me know and I will look into them.
Kind Regards,
Jas.W
12-21-2009 07:22 PM
will it work this way ???
I have the same problem ,i have set two callbacks, one for analog,others for digital,
they will not finish acquiring 10000 samples at the same time.
So if you get the data out without acuqiring 10000 samples, it will show error message
12-22-2009 04:17 AM
Hi
Yes that's why I only have the one callback the analog one and ascertain the total available digital samples before reading. In my case they always seem to be the same - is this something to do with " synchronise callbacks".
Like me you seem to be suffering from the lack of information provided by NI. If you want to use Labview or one of their other Mickey Mouse applications then there seems to be plenty of info but if you want to do proper programming using the API, as we are doing, then they don't seem very keen to help you. Must put folks off from using NI adc cards, so I can't understand the reasoning.
If you look back at this thread you see one reply from someone from NI and he didn't really seem to know the answer to my question, and I did get a phone call from someone from NI because I had downloaded one of the examples. He knew even less and promised to get back to me but never did. All a bit pathetic really. Anyway I have a system that works now so I don't need any NI help.
I have used Data Translation cards in the past and you got a proper book with all the API information and plenty of examples - pity NI don't do the same.
Merry Christmas
Ray
06-13-2013 03:13 PM
So true. They need to get the programmers to answer these questions sometimes. All the help is circular, and the comments in the code are just cutting and pasting the same thing over and over. These