LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with digital input

I am using VC++ .net to program an acquisition program for my 6024E board.
I am using the nidaqmx drivers for C and have already programmed an analog
input channel which works fine. However i now want to program a digital
channel and am wondering if i am using the wrong functions. I have kept the
DAQmxCfgSampClkTiming function from the previous program but there seems to be
a problem with it. Does anyone have the basics of writing a digital input
program?

Also if it any help, here is the code.

#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 4
(2,834 Views)
This is the LabVIEW forum. May be you could try to ask your question in the LabWindows part, here :
http://forums.ni.com/ni/board?board.id=180
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 4
(2,822 Views)
deirhack...

What is the error you are getting...that would really help. One thing it looks like is you are trying to do HW timing on the digital side? That is only supported on the new M Series boards and a few other digital boards. If you are using an E series board this won't work. Look at some of the digital examples that ship with NIDAQmx and if you let us know what board you are using and what the error you are getting we could probably help out more.

StuartG
0 Kudos
Message 3 of 4
(2,812 Views)
Sorry am in the wrond place. It was a mistake. Someone has suggested that i am trying to do hardware timing when in fact digital lines need to be software timed.
I am using an E series board so I cannot use hardware timing.
Thanks for the help.
0 Kudos
Message 4 of 4
(2,801 Views)