Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDAQmx Base and Cocoa: Creating a NIDAQ task stops my application from quitting

Hello,

 

I am writing an OS X Cocoa applciation that will interface with NI USB hardware using the NIDAQmx Base drivers and frameworks.  The porblem I have is that if I create a task at any point in my applciation, then when the applcaition terminates it will hang/crash.  This is related to using the NIDAQmx functions because if I remove any reference to NIDAQmx Base everything is fine.

 

Even if I do nothing more than:

 

DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
if(taskHandle != 0) {
   DAQmxBaseStopTask (taskHandle);
   DAQmxBaseClearTask (taskHandle);
}

It runs without errors, but my application cannot quit.  There are no errors or exceptions generated.

 

Has anyone experienced this before?

 

Am I cleaning up after the NIDAQmx task appropriately?  Is there something left that could be tying up a resource?  Is there anything I can do to clean up after the NIDAQ task better?

 

0 Kudos
Message 1 of 28
(3,804 Views)

Hi Tangle,

 

What version of DAQmx are you using?

0 Kudos
Message 2 of 28
(3,781 Views)

Dominik,

 

I am using NIDAQmx Base 3.6.  I had a the same problem with version 3.5 before the recent update.

 

Thanks

Lee.

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

Hi Lee,

 

> The porblem I have is that if I create a task at any point in my applciation, then when the applcaition terminates it will hang/crash.

 

Does it hang or does it crash?

 

If it hangs, attach a debugger and display all of the thread stacks at the time of the hang.

 

If it crashes, attach a debugger before the program crashes and display the stack at the time of the crash.

 

Either way, viewing the call stack should give you a better picture of what code is involved in the hang or crash. It won't be a complete picture, because many libraries won't have debug symbols and DAQmx Base is a LabVIEW-built library, but it's better than nothing.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 4 of 28
(3,767 Views)

Brad,

 

Thanks for you reply.

 

It's a hang.  There have been crashes but they are not reproducable and I now believe they were related to other things.

 

Attached is a stack trace of all threads from during the hang.  There is a lot of "LabView" in there including some at the top of the main thread stack, and what look to me like duplicate threads.

 

Thanks

Lee.

Download All
0 Kudos
Message 5 of 28
(3,762 Views)

Hi Lee,

 

Are you able to set up tasks in Measurement and Automation Explorer?

0 Kudos
Message 6 of 28
(3,740 Views)

Dominik,

 

MAX does not appear to be part of MIDAQmx Base, nor does it seem to be available for OS X.  The NI documentation tells me that I have to use other utilities for OS X.  However, I can see the device in lsdaq and I have sampled data using th nidatalogger app provided with NIDAQmx Base.

 

The problem is not that I can't interface with and use the hardware.  Within my application code I can create tasks and sample data, however doing so always results in a hang (with the supplied stack trace) when I quit the application after wards.  Even if I do not sample data but only create a task and then stop it and clear it (using the code in my original post) I get the hang.

 

Thanks

Lee.

0 Kudos
Message 7 of 28
(3,736 Views)

Hi Lee,

 

Have you tried using one of the examples we provide? I see that you used the DAQmxErrChk function. Did you include the #define statement for it?

0 Kudos
Message 8 of 28
(3,705 Views)

Yes and yes.

 

The problem with hanging only occurs when I interface from code I have written.  If I run the example binaries (or compile the source and run them) they appear to run fine.  That said, my applcations code is currently just a wrappered copy/paste version of the example source code.

 

I doubt it would be possible to compile without the #define statement, DAQmxErrChk would be an undefined function.

0 Kudos
Message 9 of 28
(3,701 Views)

So you see the behavior even if you simply try to call one of the examples? By that I mean, place a function around the example and call the function. Also, if you step through the code, where does it lock up?

Worst case, what you may have to do in order to isolate the problem is simply cut your code down to be more and more simple until the behavior no longer appears. Once you are at that point, start building back up. 

0 Kudos
Message 10 of 28
(3,687 Views)