LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Global tasks (handler)

I have programmed legacy DAQ cards like the 6024 using LabWindows CVI for 15 years.  Now I have to use a USB 6218 and DAQmx. I want to use a counter to measure my loop time.  If I start a task (like start the counter) in one subroutine call I can not call that same task in another subroutine call (like read the counter).  The task handler ID seems to only be a local variable.  The task or taskhandler can not be made a global variable.  If the create, start, read, stop, and clear tasks are all in the same subroutine, everything works.  I hope I am stating this problem correctly, I am an engineer who knows some programming, not a pure programmer.

0 Kudos
Message 1 of 4
(3,368 Views)

Regardless the place where it is started, a task is defined at system level: if you start a task in a function and you try to access the same resource (i.e. the same counter) from another fucntion, another source file or even a separate program you get e "reserved resource" error, meaning the task is up and running.

The task handler cannot be accessible from another function if its variable scope does not extend up to that function, but this does not mean the task is not ok.

 

How yu defined the task handler? Can you post some code from your function for we to look at it?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,363 Views)

RobertoBozzolo,

First of all, thank you kindly for your quick response and help.  I think you are onto the source of my problem.  I have attached some information to explain the code.  The program is very large.  I thought I have defined the Task Handler at the system level with a static definition.  But when I compile the code, I get a message that the task handler is undefined.

I hope I have explained my code in the attachecment well enough for you to see the problem.

I have to share with you that I have never used task handlers.  Somehow, since CVI was started I have gotten by without out it.  Right now I am not a fan of the DAQmx approach to data acquisition and control.  I used to be able to use simple easy IO or legacy library routines that were very straight forward and used a minimum of code.  I also tried defining the tasks in Measurement and Automation Explorer, but I could not get those to work also.  I thought it was just me but I talked to two other engineers who also dabble in programming and they too are not happy with the improvement. 

I think the issue is that we have to be better programmers.  Instead of just engineers who use the CVI tool.

Again, I want to thank you for any help that you can offer.

Mike

0 Kudos
Message 3 of 4
(3,339 Views)

I don't know what's happening: your code looks correct and you get an undefined error only on one variable.I can think of a typo hard to find.

I would suggest you let CVI generate the variable definition this way: view function panel for DAQmxCreateTask instruction and follow these steps:

 

DeclareVariable.png

 

CVI will create the definition of the variable at module level: you should be able to compile and execute the code without errors.

 

BTW, since you are using DAQmx functions, you don't need to include dataacq.h any more: this is the definition of Traditional DAQ functions, which you can't use in the same program as DAQmx ones.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,336 Views)