Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract data from CNiReal64Vector

I'm using MFC Visual C++ to read 3 thermo couple channels.  My partial code to read the data look like the following

 

CNiReal64Vector Data;

CNI_MFC_DAQmx_App_UserCode userCode;

userCode.GetData(Data);

 

How do I extract data out from Data variable to store into a file?  How does the data store in Data variable for all three channels?

 

Thanks,

 

Tuan Bui

0 Kudos
Message 1 of 3
(7,320 Views)

Hello Tuan,

 

I'm not too familiar with the CNiReal64Vector data type however, I suggest looking at one of our C++ Thermocouple examples that ships with Measurement Studio. This example can be found in the following directory:

 

C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\MStudioVC2005\Analog In\Measure Temperature\ContAcqThermocoupleSamples_IntClk

 

Please take a look at this example to get an idea of how you would go about programming your own application. If you still run into problems please post back to this thread.

Manooch H.
National Instruments
0 Kudos
Message 2 of 3
(7,303 Views)
 

/* Create a file to save your datalog*/

try { m_fileWrite.exceptions(ifstream::failbit | ifstream::badbit);

      m_fileWrite.open("YourDatalog.txt");

}

catch (ofstream::failure e) {   AfxMessageBox("Error opening text file.");

if (m_fileWrite.is_open()) m_fileWrite.close();

                                                 m_fileWrite.clear();

                                      return;

} }

 /*your CNiReal64Matrix data is processed into CNiReal64Vector, that is if you used these data types.  The matrix type caters to multiple signals, thermo1, thermo2 & thermo3, in your case.  The output is tabulated in column form.  Open it in excel for readability*/

int channelCount = m_data.GetRows();  int dataCount = m_data.GetCols();

// Write header

for (unsigned int j = 0; j < m_task->AIChannels.Count; j++) { m_fileWrite << m_task->AIChannels[j].PhysicalName << "\t";

}

m_fileWrite << endl;

m_outStream.str("");

CNiReal64Vector v;

// Write data

for (int i = 0; i < dataCount; i++) {  m_data.CopyColumn(i, v);

for (int j = 0; j < 1; j++) m_outStream << dec << v[j] << "\t"}

m_outStream << endl}

 

m_lTotalSamples += dataCount;

if (m_fileWrite.is_open()) m_fileWrite << m_outStream.str();

m_fileWrite.close();  }

 

This is a snippet from an analog voltage program with file I/O with few modifications.

 

0 Kudos
Message 3 of 3
(7,154 Views)