07-10-2013 09:44 PM
Hi there,
I follow the example for writing the digital line as follow
int taskHandle;
int data[8];
char linename[]="dev2/port0/line0:7";
DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
DAQmxErrChk(DAQmxCreateDOChan(taskHandle, linename, "", DAQmx_Val_ChanPerLine ));
DAQmxErrChk(DAQmxStartTask(taskHandle));
DAQmxErrChk(DAQmxWriteDigitalU8(taskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, data, NULL, NULL)); // here data has 8 numbers
Error:
SetWaitCursor(0);
if (DAQmxFailed(error)) DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle!=0)
{
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if (DAQmxFailed(error)) MessagePopup("DAQmx Error", errBuff);
The above example show how to write 8 binary to 8 lines, but how to write to only one line? I try the following code but it doesn't work
char linename[]="dev2/port0/line2";
...
DAQmxErrChk(DAQmxWriteDigitalU8(taskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data[2], NULL, NULL)); // here data has 8 numbers
Solved! Go to Solution.
07-11-2013 10:13 AM - edited 07-11-2013 10:13 AM
Hi dragon,
First, the DAQmxWriteDigitalU8 function should take a uInt8 array (1-byte integers), but you're passing it an int array (4-byte integers).
Additionally, you did not include any code where you initialize your data[] array with the values you expect to be written, but judging by the rest of your code, I suspect that you want to set each element of the array to a '1' or a '0' (wasting 7 bits for each line). For the DAQmxWriteDigitalU8() function, each individual byte in the array does not correspond to an individual line, each bit does. That data format is further elaborated here: http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/digitaldata/
If you want each byte in your uInt8 data[] array to represent a single line, then use the DAQmxWriteDigitalLines() function instead of DAQmxWriteDigitalU8().
07-11-2013 12:44 PM
@Chad_A wrote:
Hi dragon,
First, the DAQmxWriteDigitalU8 function should take a uInt8 array (1-byte integers), but you're passing it an int array (4-byte integers).
Additionally, you did not include any code where you initialize your data[] array with the values you expect to be written, but judging by the rest of your code, I suspect that you want to set each element of the array to a '1' or a '0' (wasting 7 bits for each line). For the DAQmxWriteDigitalU8() function, each individual byte in the array does not correspond to an individual line, each bit does. That data format is further elaborated here: http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/digitaldata/
If you want each byte in your uInt8 data[] array to represent a single line, then use the DAQmxWriteDigitalLines() function instead of DAQmxWriteDigitalU8().
It is confusing. In the the DAQmxCreateDOChan, I specify DAQmx_Val_ChanPerLine, so it doesn't mean each value will write to each line? I am testing to use uInt8 and DAQmxWriteDigitalLines, to see if it can write to one line only.
p.s. the data was read from 8 binary button with the values set to 0 or 1 (char).
07-11-2013 01:11 PM
The data format for the DAQmxWriteDigitalLines() function will do exactly what you want.
The data format for the DAQmxWriteDigitalU8() function corresponds to a full port (even if you don't have a full port's worth of lines in your task).