LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadDigitalU8 convert to boolean array

Hi,
I am using the DAQmxReadDigitalU8 function which returns an 8 bytes unsigned int  and I d like to convert it to a boolean array in order to light on or of the differents leds corresponding to digital values.

Is there a built in function for uInt8 to boolean array conversion

Thanks
Olivier
0 Kudos
Message 1 of 10
(4,076 Views)
Why not using DAQmxReadDigitalLines instead, that return an array of data (one element per each channel included in the task, creating one channel per digital line to read)?
 
Alternatively, individual bits can be read for example as follows (and transferred to integer values):
 
static unsigned int i, ch;    // Assuming 'ch' contains the value returned by DAQmxRead
 
ch = 0xF0;    // For testing purposes
for (i = 0; i < 8; i++) {
 DebugPrintf ("Bit %d: %d\n", i, ch & (1 << i) ? 1 : 0);
}
 


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(4,059 Views)

Hello Roberto,

 

I have a similar question like the one you answered. I actually have a NI driver 6528 having ports p0-p5. Ports 0,1,2 has 8 lines each. I am step by step writing the process, correct me where I am wrong.

I have created a taskHandle array like:

 

// DAQmx Configure Code

DAQmxCreateTask("Dev0-R0",&taskHandle[0]);
 DAQmxCreateTask("Dev0-R1",&taskHandle[1]);
DAQmxCreateTask("Dev0-R2",&taskHandle[2]);

 

/*    Creating Reading Channels        */

DAQmxCreateDIChan(taskHandle[0],"Dev0/port0/line0:7","",DAQmx_Val_ChanForAllLines);
DAQmxCreateDIChan(taskHandle[1],"Dev0/port1/line0:7","",DAQmx_Val_ChanForAllLines);
DAQmxCreateDIChan(taskHandle[2],"Dev0/port2/line0:7","",DAQmx_Val_ChanForAllLines);

 

Similarly I have created 3 global variable arrays which can read values of all the 8 lines of each port like:

uInt8 Dev0DataArr0[8] = {0,0,0,0,0,0,0,0};
uInt8 Dev0DataArr1[8] = {0,0,0,0,0,0,0,0};
uInt8 Dev0DataArr2[8] = {0,0,0,0,0,0,0,0};

 

Now if I want to read digital channels, I will call the following command:

DAQmxReadDigitalLines(taskHandle[0],1,10.0,DAQmx_Val_GroupByChannel,Dev0DataArr0,100,&read,&bytesPerSamp,NULL);

 

I have to check what I get after reading  from the hardware in the array Dev0DataArr0. I have to now see the LED action so I set values of the Dev0DataArr0 to my LED's.

 

SetCtrlVal(panel,PANEL_LED1,Dev0DataArr0 [0]);

SetCtrlVal(panel,PANEL_LED2,Dev0DataArr0 [1]);

SetCtrlVal(panel,PANEL_LED3,Dev0DataArr0 [2]);

SetCtrlVal(panel,PANEL_LED4,Dev0DataArr0 [3]);

SetCtrlVal(panel,PANEL_LED5,Dev0DataArr0 [4]);

SetCtrlVal(panel,PANEL_LED6,Dev0DataArr0 [5]);

SetCtrlVal(panel,PANEL_LED7,Dev0DataArr0 [6]);

SetCtrlVal(panel,PANEL_LED8,Dev0DataArr0 [7]);

 

 

I have to test the hardware for which I have to travel to a different place. So before that I want to make sure will this work for me as showed above.

Waiting for your response. Thank you.

 

Regards

Raunak

 

 

 

 

 

 

 

 

 

0 Kudos
Message 3 of 10
(3,444 Views)

The code looks correct. You could also read all lines in a single task by defining a channel with the string "Dev0/port0/line0:7, Dev0/port1/line0:7, Dev0/port2/line0:7" and creating an array of 24 elements.

A small correction to your code: you must pass the size of the array to DAQmxReadDigitalLines, so either you create an array with 100 elements (but the function will fill only the first 😎 or pass 8 to ArraySizeInBytes parameter.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 10
(3,440 Views)

So if I create a 24 line array and pass it into the read hardware function DAQmxReadDigitalLines , will that still read the first 8 values only (keeping ArraySizeInBytes euals to 24)?

0 Kudos
Message 5 of 10
(3,434 Views)

It depends on how you configure the channels string. The function will return a read for every channel in the task: if the tast includes only a port, it will return 8 bytes even if the array is longer. Wuat is important is that the array and the size passed to the function match one to each other.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 10
(3,420 Views)

Concluding this: - if I configure the channel like this : -  DAQmxCreateDIChan(taskHandle[0],"Dev0/port0/line0:7,Dev0/port1/line0:7,Dev0/port2/line0:7","",DAQmx_Val_ChanForAllLines);

This will then read 24 lines by passing array of 24 or even more ?

 

Am I correct?

 

0 Kudos
Message 7 of 10
(3,381 Views)

Yes: reading one sample/channel will fill a 24 elements array.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 8 of 10
(3,379 Views)

Thank u, Kudos to You

0 Kudos
Message 9 of 10
(3,377 Views)

You're welcome!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 10
(3,373 Views)