Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing an array to digital output lines

Hi all, 

 

I have a 6509 PXI module. I would like to write an array of values across multiple digital output lines. I have been looking at the NI examples, but I'm missing something. The code snippet I have, is as follows:

 

 
int PxiError = 0;
TaskHandle taskHandle=0;
uInt8 digitalWritedataArray[32] {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,};
//For sake of argument
char errBuff[2048]={'\0'};
int32 written=1;

#define DAQmxErrChk(functionCall) if( DAQmxFailed(PxiError=(functionCall)) ) goto Error; else
 
// DAQmx Configure Code
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

   
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"PXI1Slot6/port0:5","Digital Outputs 1",DAQmx_Val_ChanForAllLines));
//Activate all lines, over ports 0-5.
 
// DAQmx Start Code
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,digitalWritedataArray,&written,NULL));
//I want to write each value in 'digitalWriteArray' to each line.
 
//Error handling
Error:
 if( DAQmxFailed(PxiError) )
 DAQmxGetExtendedErrorInfo(errBuff,2048);
 if( taskHandle!=0 ) {
 
// DAQmx Stop Code
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}

 

Is this sufficient to write the array, 'digitalWritedataArray' across 32 lines, starting at port0, line 0? Or, is some loop necessary?

 

Any clarification would be great.

 

 

Thanks..

 

Paul

 

0 Kudos
Message 1 of 2
(2,089 Views)

I'm a LabVIEW guy who doesn't know the text API in any detail, but I think you might need to make a change to this code.

 

It looks like you're writing to a 32-bit port and you've configured the task to handle all lines as 1 shared channel.  Under LabVIEW (and I suspect probably also under, what, C?), you would update all 32 lines simultaneously by writing a single unsigned 32-bit integer value where each individual bit represents a line.  Line 0 is the LSB, line 31 is the MSB.

 

Another way to do things is to configure the task to treat each line as a separate channel.  Then the way to update all lines at once under LabVIEW is to write a length-32 array of booleans to the task.  It's possible (though I'm not anywhere near sure) that the text API will take a length-32 array of integers such as you have in your code. 

 

It doesn't have to matter which method you choose, but you have to keep the config and the datatype consistent.  Right now you have one from each category which probably won't do what you want.

 

As to the 2nd question, you should plan to have a loop where you write different data each iteration.  (It isn't entirely clear what your full dataset will be as the posted code appears to define only 1 single static value for all your digital lines.)  You'll likely need some kind of timing control in the loop to slow it down, and can start by using some kind of software delay function.  That's probably all you can do as I don't think your device supports hardware-timed DO.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 2
(2,010 Views)