From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot readout all ports

Dear,

 

I am a newbie with DAQ, but I'm making a small program to be able to read in some open/close contacts.

The problem I encounter, is that I can read all ports (from P0.0 through P0.7), except ports P0.1 and P0.2 ...

 

(System = Centos 5.5 with NI-DAQMX Base; Device = NI USB-6501)

 

My program responds when I close contact P0.0 as follows:

After closing P0.0 :

 

Data changed from 0xFF to 0xFE

After opening P0.0 :

 

Data changed from 0xEF to 0xFF

 

 

But with P0.1 and P0.2 it does not respond at all... ??????

 

 

 

Below my little program I have:

 

 

#include "NIDAQmxBase.h"
#include <stdio.h>

#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }

int main (int argc, char *argv[])
{
   // Task parameters
   int32       error = 0;
   TaskHandle  taskHandle = 0;
   char        errBuff[2048];

   // Channel parameters
   const char  chan[] = "Dev1/port0";

   // Read parameters
   uInt8      r_data[1], r_data_old[1];
   int32       read;

   system("lsdaq");

   // Create Digital Input (DI) Task and Channel
   DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle));
   DAQmxErrChk (DAQmxBaseCreateDIChan(taskHandle,chan,"",DAQmx_Val_ChanForAllLines));

   // Start Task (configure port)
   DAQmxErrChk (DAQmxBaseStartTask (taskHandle));

   // Read from port
   DAQmxErrChk (DAQmxBaseReadDigitalU8(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,r_data,1,&read,NULL));
   r_data_old[0]=r_data[0];
   do{
     DAQmxErrChk (DAQmxBaseReadDigitalU8(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,r_data,1,&read,NULL));
     if (r_data_old[0]!=r_data[0]){
        printf("Data changed from 0x%X to 0x%X\n", r_data_old[0], r_data[0]);
      }
      sleep(1);
   }
   while (1);

Error:

   if (DAQmxFailed (error))
      DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);

   if (taskHandle != 0)
   {
      DAQmxBaseStopTask (taskHandle);
      DAQmxBaseClearTask (taskHandle);
   }

   if (error)
      printf ("DAQmxBase Error %d: %s\n", error, errBuff);

   return 0;
}

 

 

 

 

 

 

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