Hey am trying to read digital signal from my 6024E board and although my analog program has worked i cannot get my digital program to work. I am using NIDAQmx drivers.
Here is the code if it is any help. Not sure if this is the right place to post this even. If not, someone can tell me where to go.
#include
#include
#include
using namespace std;
int main()
{
TaskHandle hMyTask;
bool32 isTaskDone;
int32 errorCode;
char errorString[1000];
float64 readArray[288];
int32 sampsPerChanRead;
int32 numBytesPerSamp;
float64 samprate = 32;
uInt64 noofsamps = 288;
cerr << "Hello from tedacq!" << endl;
// Open file to record data
ofstream data_file("test.dat", ios::binary);
// Create task
cerr << "Creating task...";
if (DAQmxCreateTask("my task", &hMyTask) == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
return 1;
}
//Add digital channel to task
cerr << "Creating digital input channel...";
errorCode = DAQmxCreateDIChan(
hMyTask,
"Dev1/port0/line0",
NULL,
DAQmx_Val_ChanPerLine);
if (errorCode == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
DAQmxGetErrorString (errorCode, errorString, 1000);
cerr << errorString << endl;
}
//set sampling rate etc for task
/*cerr << "Configuring sampling rate etc...";
errorCode = DAQmxCfgImplicitTiming(
hMyTask,
DAQmx_Val_FiniteSamps, //samplemode
noofsamps);
if (errorCode == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
DAQmxGetErrorString (errorCode, errorString, 1000);
cerr << errorString << endl;
}*/
// Set sampling rate etc for task
cerr << "Configuring sampling rate etc...";
errorCode = DAQmxCfgSampClkTiming(
hMyTask,
NULL, // Clock source - NULL for internal
32, // sampling rate
DAQmx_Val_Rising, // Acquire sample on rising clock edge
DAQmx_Val_FiniteSamps, // Acquire a finite number of samples
288);
if(errorCode == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
DAQmxGetErrorString (errorCode, errorString, 1000);
cerr << errorString << endl;
}
// Start task
cerr << "Starting task...";
if (DAQmxStartTask(hMyTask) == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
}
// Wait for task to finish
cerr << "Querying task status...";
while (true)
{
if (DAQmxIsTaskDone(hMyTask, &isTaskDone) == 0)
{
// Query was successful
if (isTaskDone)
{
cerr << "Done" << endl;
break;
}
else
{
cerr << ".";
}
}
else
{
// Query was unsuccessful
cerr << endl << "Error querying task.";
break;
}
}
//Read samples
cerr << "Reading Samples...";
errorCode = DAQmxReadCounterF64(
hMyTask,
288, //int32 numSampsPerChan
-1, //float64 timeout
readArray, //float64 readArray[]
288, //uInt32 arraySizeInSamps
&sampsPerChanRead, //int32 *sampsPerChanRead
NULL);//bool32 *reserved
if (errorCode == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
DAQmxGetErrorString (errorCode, errorString, 1000);
cerr << errorString << endl;
}
//// Read samples
//cerr << "Reading samples...";
//errorCode = DAQmxReadDigitalLines(
// hMyTask, //taskhandle
// 288, // int32 numSampsPerChan
// 1, // float64 timeout,
// DAQmx_Val_GroupByChannel, // bool32 fillMode,
// readArray, // uInt8 readArray[]
// 288, // uInt32 arraySizeInBytes,
// &sampsPerChannelRead, // int32 *sampsPerChanRead,
// &numBytesPerSamp, //int32 *numBytesPerSamp,
// NULL // bool32 *reserved,
// );
//if (errorCode == 0)
//{
// cerr << "OK" << endl;
//}
//else
//{
// cerr << "Error" << endl;
// DAQmxGetErrorString (errorCode, errorString, 1000);
// cerr << errorString << endl;
//}
// Stop task
cerr << "Stopping task...";
if (DAQmxStopTask(hMyTask) == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error" << endl;
}
// Clear task
cerr << "Clearing task...";
if (DAQmxClearTask(hMyTask) == 0)
{
cerr << "OK" << endl;
}
else
{
cerr << "Error destroying task" << endl;
}
// Write data to file
for (int n=0 ; n<288 ; ++n)
{
data_file << readArray[n] << endl;
}
// Close file
data_file.close();
}