03-06-2006 02:47 PM
03-07-2006
11:02 AM
- last edited on
11-16-2025
12:14 PM
by
Content Cleaner
The CNiDAQmxStream class provides the ReadRawXXX methods for you.
03-08-2006 08:18 AM
Thanks Bilal,
I have been trying to use to CNiDAQmxStream class in my project but am stuck at a point. THe help documentation says CNiDAQmxStream can be used to control reading and writing behavior and can be used in conjunction with reader and writer classes to read or write samples to or from a DAQmx task.
So do I need to create reader for a task or I just use CNiDAQmxStream to read the buffers? I would like to assign reader to the task and use EventHandelr function where to do the actual read.
The example you pointed to does the actual buffer read in Timer function but I like the event handler functionality better.
my code snippet is as shown below, please take a look at the comments in the code below
===================================
Configure_Card_Function()
{
// Create task for Dev1
m_task = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask());
// Create voltage input channels
m_task->AIChannels.CreateVoltageChannel("Dev1/ai0:7","",DAQmxAITerminalConfigurationRse,-10, 500, DAQmxAIVoltageUnitsVolts);
// Setup sampling clock
m_task->Timing.ConfigureSampleClock("", 2000, DAQmxSampleClockActiveEdgeRising, DAQmxSampleQuantityModeContinuousSamples, 1000);
// Change input buffer default size to read 100 samples / channel / read
m_task->GetStream().ConfigureInputBuffer(100);
// verify the task is correct
m_task->Control(DAQmxTaskVerify);
// setup unscaled channel reader .. do I need to ??
m_reader = std::auto_ptr<CNiDAQmxAnalogUnscaledReader>(new CNiDAQmxAnalogUnscaledReader(m_task->Stream));
// Set up event handler for Buffer Read event
m_reader->InstallEventHandler(*this, OnBufferReadDev1);
// ???? do I explicitly start the task here?
m_task->Start();
// OR I call the read function associate with attached reader
m_reader->ReaUInt16();
// OR call read associated with CNiDAQmxStream class ?
m_task->Stream.ReadRawUInt16(100,m_data);
}
// Event associated with reader ..
OnBufferReadDev1(......)
{
// ???? I guess this event only gets fired if I call the read function on m_reader
// so can i write the code below in this function?
CNiComInitialize com(CNiComInitialize::Apartment);
try {
asyncHandle.CheckForAsyncException();
m_task->Stream.ReadRawUInt16(100,m_data);
}
catch (CException* e) {
e->ReportError();
e->Delete();
}
}
==================================
Thanks
03-09-2006 12:22 PM
03-09-2006 02:03 PM
03-10-2006 03:03 PM
03-13-2006 07:38 AM
Ryan,
I want the data output in the form of CNiUInt16Vector and not Matrix.
That’s the main reason for me trying to use CNiDAQmxStream and not the examples provided by NI.
All the examples provided by NI have data output in the form of Matrix. Even the methods you have suggested return data in the form of Matrix.
Bilal (in reply 2) had pointed me to an example that uses CNiDAQmxStream but it has windows timer inbuilt. Instead of timers I want to use event handlers. How to do it is the question.
03-15-2006 05:20 PM