Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ Worker Thread - Quit Task

I have an installation of DAQmx on Linux with an 6221 PCI card. My software contains a C++ class which contains a worker thread.

 

I setup a digital read using various functions from DAQmx and then DAQmxReadDigitalLines. This works in a simplistic way and either quits with an error code (becuase no IO changes have accurred), or if I set WaitInfinitely returns from the function with a number of samples.

 

So thus far all works OK.The problem I have if I want to quit cleanly with this functionaility in a worker thread. 

 

I have a worker thread so the class interface can be accessed by a statemachine without being blocked or having to wait. I plan to have 2 other threads containing tasks collecting and writing analogue samples.

 

The problem Im facing is if I 'WaitInfinitely', (so the thread is blocked by DAQmxReadDigitalLines waiting for a change to occurr) and call DAQmxStopTask from an object member (with the unit32 task handle), I get a segmentation error and the task doesnt quit.

 

I could go down the route of checking a continue flag every loop of the a finite timeout instead of WaitInfinitely, but I have made an exception class DAQmxErrChk so its awkard and besides, surely the best method is to have the task waiting for a change and to be able to stop it. I dont want to miss any in handling the timeout durations ever few seconds!

 

I dont want to forcefull quit the thread as that may leave DAQmx in a bad state.

 

Surely there is a method to gracefully quit blocking tasks?

0 Kudos
Message 1 of 4
(6,128 Views)

Ive also tried DAQmxTaskControl(task, DAQmx_Val_Task_Abort) and DAQmxTaskControl(task, DAQmx_Val_Task_Stop);

 

This also just gives a "Segmentation fault".

 

Is this becuase youre not supposed to interrupt DAQmxReadDigitalLines() when DAQmx_Val_WaitInfinitely is set?

 

The problem is I need to monitor certain lines in the background and verify that they dont change BUT also need to quit whenever the user wants and allow this by software.

0 Kudos
Message 2 of 4
(6,127 Views)

 

 

ok Ive found this:

http://digital.ni.com/public.nsf/websearch/EB202A78FB1D083186257117005CEF21?OpenDocument

 

Ive tried the GCC flag, and linking -ldl as the first library but I still get a segmentation fault if I try to use any of the calls to end the task early.

 

Smiley Mad

0 Kudos
Message 3 of 4
(6,122 Views)

OK, it was the number of samples and the buffer id supplied. The task inside a thread, controlled from the outside is now working as expected 🙂

 

 

0 Kudos
Message 4 of 4
(6,110 Views)