LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

sequencing job

Hi,

I have a question about doing jobs sequentially. That is, do it one after one in terms of time. For example,
------------------------------------------------------------------
SetCtrlVal (panelHandle, PANEL_LED1, 1);  //step 1
SetCtrlVal (panelHandle, PANEL_LED2, 1);   //step 2
Delay (3);  //step 3
SetCtrlVal (panelHandle, PANEL_LED3, 1);   //step 4
-------------------------------------------------------------------

How can I make the program run step 1 , then step 2, then delay for 3 seconds (step 3) and then run step 4?
when I run the above code in one functon, it delays 3 seconds firstly before it set the control values.
Thanks a lot!

Joyce
University of California, Santa Cruz
0 Kudos
Message 1 of 10
(3,763 Views)
What you are really seeing are the control being updated ON THE SCREEN after the 3 secs wait. This is because your user interface is not updated after each individual step, so you have no visual effect of what the program is doing. Adding some ProcessDrawEvents () functions after control update will show the results of control updates even before the function terminates.


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
(3,760 Views)
....or define a UIR timer with your 3 steps in it as a state machine (each
step prepares for the next and set the timer duration for the appropriate
wait)
--
Guillaume Dargaud
http://www.gdargaud.net/


0 Kudos
Message 3 of 10
(3,752 Views)
Thanks for the replyings.
Roberto, do  you mean that in Labwindows, it actually runs the code line by line? If I want to run a certain step earlier than the other step, I can just put it in front?
Guillaume, how to use timer() function?
Are there any timer() function examples for sequential jobs?

Thanks,
Joyce
0 Kudos
Message 4 of 10
(3,723 Views)
Do  you mean that in Labwindows, it actually runs the code line by line? If I want to run a certain step earlier than the other step (for example, read some data into hardware), I can just put it in front? or is it just the case for SetCtrlVal?

Thanks
Joyce
0 Kudos
Message 5 of 10
(3,717 Views)

It is exactly what I am saying: unless some special actions are taken to alter this mechanism, instructions are executed sequentially as they are written in the code! So you can for example prepare an acquisition task and run it simply writing the instruction in this exact order, or query a device via RS232 and wait for response simply putting the reading function after the polling one.

Timers and multithreading are common ways to alter this mechanism adding sections of code executed independently from the rest of the program.



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
(3,713 Views)
Thanks, Roberto.
I am writing a program that can automatically run a series jobs sequentially. Now the other problem is that I dont know how to stop the program. It seems that when it is running, others controls on the UI are not enabled. Does Delay function actually lock UI? Is there any waiting function I can use that won't do that?

thanks a lot!!
Joyce
0 Kudos
Message 7 of 10
(3,692 Views)
Your problem os that while inside a tight loop the system does not automatically handles pending UI events nor any other event like a timer callback. To ensure the you are processing system events inside a loop you should periodically call ProcessSystemEvents () to permit handling the event queue. You must be careful while doing so, since you cannot specify which event is processed and which not: ALL pending events are processed so you may need to delimit possible user operations other ways (for example disabling controls that are not relevant or are forbidden in such a condition).
 
ProcessSystemEvents is well described in the online help and was often covered by discussion here in the forum, so you can find several informations about it.


Message Edited by Roberto Bozzolo on 01-18-2008 07:08 AM


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 8 of 10
(3,690 Views)
But the problem is, when I run the sequential job. I can not abort it in the middle of the running.
For example, when I click "Run" in the UI, I let the program running the following steps:
---------------------------------------------------------------------
SetCtrlVal (panelHandle, PANEL_LED1, 1);
SetCtrlVal (panelHandle, PANEL_LED2, 1); 
ProcessDrawEvents ();
Delay (5); 
SetCtrlVal (panelHandle, PANEL_LED3, 1); 
ProcessDrawEvents () ;
Delay (2);
SetCtrlVal (panelHandle, PANEL_LED4, 1); 
-------------------------------------------------------------------
But if I want to abort it at the first Delay(3), what should I do? The screen is locked out so I can not enable any other controls. Even I use ProcessSystemEvents, that doesn't help.

Thanks a lot!
Joyce
0 Kudos
Message 9 of 10
(3,631 Views)
Well, you can simply transform you Delay () in an "active" loop:
 
double   tini;
 
tini = Timer ();
while (Timer () - tini < 3.0) {
   ProcessSystemEvents ();
   if (abort) {
      // Your code to stop the process goes here
   }
}


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 10 of 10
(3,626 Views)