Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

problems with digital input for nidaqmx?

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();
}
0 Kudos
Message 1 of 2
(3,183 Views)
>> DAQmxCfgSampClkTiming

Looks like you're trying to use internal timing for the digital lines. The digital subsystem on the 6024E doesn't have internal clocks, so that's not going to work. You can only use software timing with the digital lines on this board. Also, you're trying to read a counter value from your digital task, which is not going to work either. The NI-DAQmx ANSI C digital examples that are installed with DAQmx should give you a good place from which to start.

Good luck,
Joe
0 Kudos
Message 2 of 2
(3,135 Views)