08-26-2013 06:40 AM
I have managed to make working port output, but now I need to use only 0,1,2,3,7 lines of port 2 to set there a values not affecting the 4,5,6 lines.
I made a task with assignment:
DAQmxErrChk(DAQmxCreateDOChan(taskOut, "ioDev/port2/line7",
"DigitalOut_0", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "H1B1.7", DAQmx_DO_InvertLines, 0));
DAQmxErrChk(DAQmxCreateDOChan(taskOut, "ioDev/port2/line3",
"DigitalOut_1", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "H1B1.3", DAQmx_DO_InvertLines, 0));
DAQmxErrChk(DAQmxCreateDOChan(taskOut, "ioDev/port2/line2",
"DigitalOut_2", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "H1B1.2", DAQmx_DO_InvertLines, 0));
DAQmxErrChk(DAQmxCreateDOChan(taskOut, "ioDev/port2/line1",
"DigitalOut_3", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "H1B1.1", DAQmx_DO_InvertLines, 0));
DAQmxErrChk(DAQmxCreateDOChan(taskOut, "ioDev/port2/line0",
"DigitalOut_7", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "H1B1.0", DAQmx_DO_InvertLines, 0));
in the input of my function I get |uInt8 word|, and I need to make some function to set those 0,1,2,3,7 having as a source that word.
How to operate DAQmxWriteDigitalLines, to set only 0,1,2,3,7 bits of the port with the assignment that I made above.
Thank you very much in advance
Chris
Solved! Go to Solution.
08-27-2013 03:50 AM
I have even developed it to that version, and it do not work.
int setH1B1(uInt8 word)
{
int status=1;
uInt32 samp;
uInt8 data[8];
// Here NI-DAQ function to set Port 1 B
TaskHandle line0,line1,line2,line3,line7;
uInt8 out0,out1,out2,out3,out7;
DAQmxErrChk (DAQmxCreateTask("LINE0",&line0));
DAQmxErrChk(DAQmxCreateDOChan(line0, "ioDev/port2/line0",
"DigitalOut_0", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(line0, "DigitalOut_0", DAQmx_DO_InvertLines, 1));
DAQmxErrChk (DAQmxCreateTask("LINE1",&line1));
DAQmxErrChk(DAQmxCreateDOChan(line1, "ioDev/port2/line1",
"DigitalOut_1", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(line1, "DigitalOut_1", DAQmx_DO_InvertLines, 1));
DAQmxErrChk (DAQmxCreateTask("LINE2",&line2));
DAQmxErrChk(DAQmxCreateDOChan(line2, "ioDev/port2/line2",
"DigitalOut_2", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(line2, "DigitalOut_2", DAQmx_DO_InvertLines, 1));
DAQmxErrChk (DAQmxCreateTask("LINE3",&line3));
DAQmxErrChk(DAQmxCreateDOChan(line3, "ioDev/port2/line3",
"DigitalOut_3", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(line3, "DigitalOut_3", DAQmx_DO_InvertLines, 1));
DAQmxErrChk (DAQmxCreateTask("LINE7",&line7));
DAQmxErrChk(DAQmxCreateDOChan(line7, "ioDev/port2/line7",
"DigitalOut_7", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute(line7, "DigitalOut_7", DAQmx_DO_InvertLines, 1));
(out0)=(uInt8)(word & 0b00000001)?1:0;
(out1)=(uInt8)(word & 0b00000010)?1:0;
(out2)=(uInt8)(word & 0b00000100)?1:0;
(out3)=(uInt8)(word & 0b00001000)?1:0;
(out7)=(uInt8)(word & 0b10000000)?1:0;
DAQmxErrChk (DAQmxWriteDigitalLines(line0,1,1,10.0,DAQmx_Val_GroupByChannel,&out0,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line1,1,1,10.0,DAQmx_Val_GroupByChannel,&out1,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line2,1,1,10.0,DAQmx_Val_GroupByChannel,&out2,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line3,1,1,10.0,DAQmx_Val_GroupByChannel,&out3,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line7,1,1,10.0,DAQmx_Val_GroupByChannel,&out7,NULL,NULL));
DAQmxErrChk (DAQmxStopTask(taskHandleH1B1));
ErrorDaQ:
SetWaitCursor(0);
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandleH1B1!=0 )
{
DAQmxStopTask(taskHandleH1B1);
// DAQmxClearTask(taskHandleH1B1);
}
if( DAQmxFailed(error) )MessagePopup("CONNECTION LOST",errBuff);
return status;
}
08-28-2013 12:43 AM
Final WORKING solution.
Made like by kindergarden student, but solution is fine:
int32 CreateH1B1(void)
{
int32 DAQmxError = DAQmxSuccess;
DAQmxErrChk (DAQmxCreateTask("LINE0",&line0));
DAQmxErrChk(DAQmxCreateDOChan(line0, "ioDev/port2/line0",
"DigitalOut_0", DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateTask("LINE1",&line1));
DAQmxErrChk(DAQmxCreateDOChan(line1, "ioDev/port2/line1",
"DigitalOut_1", DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateTask("LINE2",&line2));
DAQmxErrChk(DAQmxCreateDOChan(line2, "ioDev/port2/line2",
"DigitalOut_2", DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateTask("LINE3",&line3));
DAQmxErrChk(DAQmxCreateDOChan(line3, "ioDev/port2/line3",
"DigitalOut_3", DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateTask("LINE7",&line7));
DAQmxErrChk(DAQmxCreateDOChan(line7, "ioDev/port2/line7",
"DigitalOut_7", DAQmx_Val_ChanPerLine));
Error:
return DAQmxError;
}
int setH1B1(uInt8 word)
{
int status=1;
uInt32 samp;
uInt8 out0,out1,out2,out3,out7;
(out0)=(uInt8)(word & 0b00000001)?1:0;
(out1)=(uInt8)(word & 0b00000010)?1:0;
(out2)=(uInt8)(word & 0b00000100)?1:0;
(out3)=(uInt8)(word & 0b00001000)?1:0;
(out7)=(uInt8)(word & 0b10000000)?1:0;
DAQmxErrChk (DAQmxStartTask(line0));
DAQmxErrChk (DAQmxStartTask(line1));
DAQmxErrChk (DAQmxStartTask(line2));
DAQmxErrChk (DAQmxStartTask(line3));
DAQmxErrChk (DAQmxStartTask(line7));
DAQmxErrChk (DAQmxWriteDigitalLines(line0,1,1,10.0,DAQmx_Val_GroupByChannel,&out0,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line1,1,1,10.0,DAQmx_Val_GroupByChannel,&out1,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line2,1,1,10.0,DAQmx_Val_GroupByChannel,&out2,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line3,1,1,10.0,DAQmx_Val_GroupByChannel,&out3,NULL,NULL));
DAQmxErrChk (DAQmxWriteDigitalLines(line7,1,1,10.0,DAQmx_Val_GroupByChannel,&out7,NULL,NULL));
DAQmxErrChk (DAQmxStopTask(line0));
DAQmxErrChk (DAQmxStopTask(line1));
DAQmxErrChk (DAQmxStopTask(line2));
DAQmxErrChk (DAQmxStopTask(line3));
DAQmxErrChk (DAQmxStopTask(line7));
ErrorDaQ:
SetWaitCursor(0);
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( DAQmxFailed(error) )MessagePopup("CONNECTION LOST",errBuff);
return status;
}
Best
Chris
05-13-2016 05:51 AM
Hello Friends,
I am using Labwindows along with NI-DAQmx. I am creating a GUI with which I have to connect the hardware NI-6528. My question is can I create digital channel with 48 lines and using two different devices (Dev0, Dev1) as shown below:
DAQmxCreateDIChan(taskHandle,"Dev1/port0/line0:7,Dev1/port1/line0:7,Dev1/port2/line0:7,Dev2/port0/line0:7,Dev2/port1/line0:7","",DAQmx_Val_ChanForAllLines);
Thank you in advance!
Best Regards
Raunak