Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadRaw equivalent function for Measurement Studio for VS .NET 2003

Hi,

I am trying to get raw data from USB 6009 in raw format and could not find a equivalent function to DAQmxReadRaw() function  that is present in DAQmx for C.

Is there any function in Measurement Studio equivalent to
DAQmxReadRaw()? I want the data in unscaled and interleaved format.

I dont want to use
DAQmxReadRaw() because my code will then have half C functions and all the rest built using C++ in MFC.

Please help.

THanks.

Anirudha
0 Kudos
Message 1 of 8
(4,897 Views)


The CNiDAQmxStream class provides the ReadRawXXX methods for you.

Bilal Durrani
NI
0 Kudos
Message 2 of 8
(4,893 Views)

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

0 Kudos
Message 3 of 8
(4,887 Views)
Anirudha,

For a continuous task, you should set up a reader as well as a callback to read from the task. See the following code squence:

analogInReader= new AnalogMultiChannelReader(myTask.Stream);

analogInReader.SynchronizingObject = this;
analogCallback = new AsyncCallback(AnalogInCallback);
                          
analogInReader.BeginReadMultiSample(Convert.ToInt32(samplesPerChannelNumeric.Value), analogCallback, null);

For an example of continuous analog input, please check the "ContAcqVoltageSamples_IntClk" example, which should be installed to the following directory, by default:

C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk\Cs

Hope this helps,





Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 4 of 8
(4,863 Views)
Ryan,

I can not use the BeginReadMultiSample (or alike) functions associated with any reader classes (MultiChannelReader, UnscaledReader OR SingleChannelReader) because the data returned by those functions is not interleaved and is in the form of 2D matrix.

So I want to use CNiDAQmxStream class data reading function
ReadRawUInt16. [m_task->Stream.ReadRawUInt16(100,m_data)]

The problem I am facing is that I do not know how to create a event handler when using CNiDAQmxStream class. What I need is a event that will fire after N number of samples are ready to be read (something like a timer)

I tried creating a
AnalogMultiChannelReader and added a EventHandler function for analogInReader, . But in order for the event to get fire I need to call BeginReadMultiSample on the analogInReader, which is exactly what I dont want to do.

btw sorry I forgot to mention I am using VC++, MFC

Hope what I am trying to say makes sense to you.

THanks.


0 Kudos
Message 5 of 8
(4,864 Views)
Anirudha,

Sorry about that... I thought you were using C# .NET. Instead of using the ReadMultiSample method, you should be using the ReadInt32Async or Read16Async method. These accept data of type CNiInt32Matrix and CNiInt16Matrix, respectively. Of course, you will have to change the declaration of your reader to std::auto_ptr<CNiDAQmxAnalogUnscaledReader>. I was able to successfully modify the example located in C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\DAQmx\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk to read raw data with minimal effort. Please let us know if you have any additional questions.

Regards,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 6 of 8
(4,851 Views)

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.

0 Kudos
Message 7 of 8
(4,843 Views)
Anirudha,

I now understand what you are trying to do. The problem is that I don't think the "every N samples" type event is exposed outside of a reader. That is why our example uses a timer. I suppose you could set up a counter pulse generation task to generate counter pulses using the AI Sample clock as your counter source. Then, you could add a CNiDAQmxCounterOutputEvent callback and read your analog data in there. This would use more of your hardware, but I think it would give you the software functionality you desire.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 8 of 8
(4,818 Views)