LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

create a task in cvi

Solved!
Go to solution

I want to create a task which will be cyclical called (10ms,50ms,100ms).

In this task I want to call a function.

 

Shown below is the main call of my programm.

When the userinterface is created and started the programm stand in the following position (errChk (RunUserInterface ());)

So it is impossible to place a while(1){} Loop in the main.

 

int main (int argc, char *argv[])
{
 int error = 0;
 
 /* initialize and load resources */
 nullChk (InitCVIRTE (0, argv, 0));
 errChk (panelHandle = LoadPanel (0, "Test1.uir", PANEL));
 
 /* display the panel and run the user interface */
 errChk (DisplayPanel (panelHandle));

 errChk (RunUserInterface ());   
Error:
 /* clean up */
 if (panelHandle > 0)
  DiscardPanel (panelHandle);
 return 0;
}

 

Thank you for your support. Smiley Happy

0 Kudos
Message 1 of 10
(5,242 Views)

A periodic task can be solved by using a timer: you can place a timer control on your main panel and associate a callback to it: the callback will be called at regular intervals, your function code can be put inside the timer callback.

When programming with timers, it is important not to lock the system with the periodic task; that is, a task that is to be called every 10 ms must absolutely last less than that time in order to permit handling the UI; as a rough measure consider to have timer callback to last 40-50% of the timer interval.

With a timer control you are handling both the UI and the timed task in the user interface thread: a more efficient way of addressing similar scenarios is to move to multithreaded structures, e.g. with the use of asynchronous timers. Nevertheless, if you have little or no experience on using timers I suggest you start firstly with the easiest way (the timer control) and move to multithreading only when you master 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 10
(5,218 Views)

Thank you for your support.

 

I have create a timer control in the GUI. It works but it lock the system. I call it every 1s.

 

Can you give me an examle for the second way to create tasks (multithreading)?

 

 

0 Kudos
Message 3 of 10
(5,192 Views)

@Basta87 wrote:

 

When the userinterface is created and started the programm stand in the following position (errChk (RunUserInterface ());)

So it is impossible to place a while(1){} Loop in the main.

 


The RunUserInterface function is actually a while loop with event processing capability. It waits inside a loop and calls callback functions whenever certain events happen. So you do not need to write such a loop. It is built-in.

What are you trying to do every 1 seconds?

Can you tell us about that periodic task you are trying to implement?

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 10
(5,184 Views)

I want to read a RS232 connection every second.

 

Thank you for your support.

0 Kudos
Message 5 of 10
(5,180 Views)

Hello, are you the same as Basta87?

It seems to me that you should trim your RS232 acquisition function before moving to a more complex scenario. CVI can indeed communicate through the serial channel but the communications function must be setup properly to not lock up the system. This is what you should do at first.

Can you give us some detail about the communications function? Can you show us your code?



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 6 of 10
(5,174 Views)

Now I generate the ComRead when I push a button.

When I put the ComRead in a loop(1) then I can't control the other coponents of the gui.

0 Kudos
Message 7 of 10
(5,158 Views)

A while (1) loop will block the system for sure! Every control callback must not be long lasting: this is valid for timers too. 

You should not put an infinite loop in the timer callback; consider the timer more or less as a button,  with the difference that the system takes care for you to trigger it at a regular interval.  That is: on EVENT_TIMER_TICK event you must read the com only once; the system will automatically fire this routine every second or whichever interval you set the timer to. 



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?
Message 8 of 10
(5,154 Views)
Solution
Accepted by Basta87

No need to create a new task for com read, just install a callback function for the cop port and each time a com event is generated, your callback funtion is called and you can take care of the event  

0 Kudos
Message 9 of 10
(5,142 Views)

Thank you. Can you give me an example how the Com Callback looks like?

0 Kudos
Message 10 of 10
(5,131 Views)