LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxBase M-Series, can't read AND write

It appears that with NiDAQmxBase 1.5 on linux and M-Series boards, I cannot create both a read and a write task.  I can only read, or I can only write, but if I try to set one port as read, and the other as write, neither works.  I altered one of the examples to illustrate:




#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  readTask = 0;
   TaskHandle  writeTask = 0;
   char        errBuff[2048];

   // Channel parameters
   const char  readchan[] = "Dev1/port1/line0";
   const char  writechan[] = "Dev1/port0/line0";

   // Read parameters
   uInt8       r_data [1];
   uInt8       r_data2 [1];
   uInt8       w_data [1];
   uInt8       w_data2 [1];
   int32       read;
   int32       written;

   r_data[0] = 0x9;

   w_data[0] = 0xF;

   // Create Digital Input (DI) Task and Channel
   DAQmxErrChk (DAQmxBaseCreateTask ("", &readTask));
   DAQmxErrChk (DAQmxBaseCreateTask ("", &writeTask));
   DAQmxErrChk (DAQmxBaseCreateDIChan(readTask,readchan,"",DAQmx_Val_ChanForAllLines));
   DAQmxErrChk (DAQmxBaseCreateDOChan(writeTask,writechan,"",DAQmx_Val_ChanForAllLines));

   // Start Task (configure port)
   DAQmxErrChk (DAQmxBaseStartTask (readTask));
   DAQmxErrChk (DAQmxBaseStartTask (writeTask));

   //Write to port
   DAQmxErrChk (DAQmxBaseWriteDigitalU8(writeTask,1,1,10.0,DAQmx_Val_GroupByChannel,w_data,&written,NULL));
   w_data[0] = 0x0;
   sleep(1);
   DAQmxErrChk (DAQmxBaseWriteDigitalU8(writeTask,1,1,10.0,DAQmx_Val_GroupByChannel,w_data,&written,NULL));

   // Read from port
   DAQmxErrChk (DAQmxBaseReadDigitalU8(readTask,1,10.0,DAQmx_Val_GroupByChannel,r_data,1,&read,NULL));

   fprintf(stderr, "Data read: 0x%X\n", r_data[0]);

Error:

   if (DAQmxFailed (error))
//      DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);
        perror("DAQ: ");

   if (readTask != 0 || writeTask != 0)
   {
      DAQmxBaseStopTask (readTask);
      DAQmxBaseStopTask (writeTask);
      DAQmxBaseClearTask (readTask);
      DAQmxBaseClearTask (writeTask);
   }

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

   return 0;
}
0 Kudos
Message 1 of 5
(3,145 Views)

Hello kubilus1,

The NI-DAQmx Version 8.0 for Linux driver was released recently.  I would reccomend trying this new driver and seeing if you get the same behavior.

 
Eric
DE For Life!
0 Kudos
Message 2 of 5
(3,103 Views)
I'm I going crazy, or is anyone else having trouble getting the new NIDaqMX 8.0 linux working with fork()?  Also, will compile but WILL segfault if trying to use pthreads.  Just compile it in and watch it crash.

The no fork() is a HUGE problem for me, pretty much a showstopper.

What's going on here?
0 Kudos
Message 3 of 5
(3,093 Views)

Hi,

The README for DAQmx 8.0 for Linux has some information on pthread:

Linking with the pthread Library
--------------------------------
In C or C++, use care if your NI-DAQmx application links to the Linux pthread
library. It is recommended to link your application with the gcc -pthread flag
instead of linking directly with, for instance, -lpthread. Incorrect linking
can lead to segmentation faults when the NI-DAQmx libraries load. If, after
replacing -lpthread, you still get a segmentation fault when loading NI-DAQmx,
you must explicitly link the dl library (-ldl) as the first library in your
list.

Also, one of my colleagues suggested that you should be using fork as soon as possible before calling any NI API or 
else the child process could potentially die/segfault.

Please let me know if this helps.

 

Thanks,

Salvador Santolucito

0 Kudos
Message 4 of 5
(3,070 Views)

For the fork() issue, if you use

DAQmxErrChk (DAQmxTaskControl(<your task handle>,DAQmx_Val_Task_Unreserve));

after each run of the task, it should solve your problems. It's annoying, but it works for me.

0 Kudos
Message 5 of 5
(2,945 Views)