Linux Users

cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring ports and lines

Hi

Hardware USB-6009, OS FedoraCore 6 (Redhat WS4), Driver NIdaqmxBase, S/W ANSI C.

I'm trying to read the digital lines of the two  ports on this DAQ. I have tried the examples which are only for reading ports only and they work. The DAQ has a Port 0 with 8 lines and a Port 1 with 4 lines. I would like to read each and then display the result to the screen but I display 1 line at a time, I beieve it displays all line in the port as one HEX number. How can I split the data for each port into the different lines. Below is an extract of how I'm trying to do it:

TaskHandle   taskHandle = 0;

TaskHandle   taskHandle1 = 0;

char         chan1[] = "Dev1/port0/line0:7";
char         chan2[] = "Dev1/port1/line0:3";

uInt32       r_data [8];
uInt32      r1_data [4];
int32        read=0;
int32        read1=0;

DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle));
DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle1));
DAQmxErrChk (DAQmxBaseCreateDIChan(taskHandle,chan1,NULL,DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxBaseCreateDIChan(taskHandle1,chan2,NULL,DAQmx_Val_ChanForAllLines));

DAQmxErrChk (DAQmxBaseStartTask (taskHandle));
DAQmxErrChk (DAQmxBaseStartTask (taskHandle1));

DAQmxErrChk (DAQmxBaseReadDigitalU32(taskHandle,1,1.0,DAQmx_Val_GroupByChannel,r_data,8,&read,NULL));
DAQmxErrChk (DAQmxBaseReadDigitalU32(taskHandle1,1,1.0,DAQmx_Val_GroupByChannel,r1_data,4,&read1,NULL));

  for(i=0; i<8; i++)
      {printf("Data read port 0, line %d: 0x%X\n", i, r_data);
        printf("read functions : %d\n", read1);

}

  for(i=0; i<4; i++) {
        printf("Data read port 1, line %d: 0x%X\n", i, r1_data);
        printf("read functions : %d\n", read1);
}

This is how I interpreted to read the mutlipe lines for each port. When I turn the switches on and off only the first line number changes all.

Im not sure what im doing wrong.

Regards

Thivash

0 Kudos
Message 1 of 3
(3,479 Views)

You probably want to do something like this instead:

for (i=0; i<8; i++) {

    printf("Data read port 0, line %d: 0x%X\n", i, (r_data[0] >> i) & 1);
    printf("read functions : %d\n", read);

}

for (i=0; i<4; i++) {
        printf("Data read port 1, line %d: 0x%X\n", i, (r1_data[0] >> i) & 1);
        printf("read functions : %d\n", read1);
}

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 3
(2,812 Views)

THANK YOU, so much!

It works like perfectly!

0 Kudos
Message 3 of 3
(2,812 Views)