02-11-2008 06:49 AM
02-12-2008 08:01 AM
04-15-2016 04:05 AM
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
04-15-2016 05:02 AM - edited 04-15-2016 05:03 AM
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.
04-15-2016 05:38 AM
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)?
04-15-2016 10:28 AM - edited 04-15-2016 10:29 AM
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.
04-18-2016 10:17 AM
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?
04-18-2016 10:23 AM
Yes: reading one sample/channel will fill a 24 elements array.
04-18-2016 10:25 AM
Thank u, Kudos to You
04-18-2016 10:39 AM
You're welcome!