LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop, timed structure of event structure is better?


@tiho wrote:

May I use in all while loops event structures. Now I control all devices in one while loop and one event structure in it.


You want one loop with an event structure.  All of the other loops just use a Dequeue Element.  That way they only react when they get the command.

 

Perhaps it would help if you supplied some code for us to look at.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 11 of 19
(771 Views)

Hi

 

Thank you for your answers. Here is my code. I am using one while loop and one event structure for all devices control. On this way the events are executed sequentially. You said that I have to use one main while loop with one event structure and different while loops for the different devices. The user interface is the main while loop with the event structure as I understood. What I have to put inside the event structure (the functionality of all buttons par example)? Where to put the initialization of the different devices and where to put the buttons for starting any function of the devices as moving along any axis or displaying each frame of the camera?

I understood that it is better to use queue elements for communication between multiple while loops. I didn't understand how to separate the code between the main while loop and the other while loops.

 

Best regards  

0 Kudos
Message 12 of 19
(723 Views)

One while loop can work fine, it depends on how long each event takes to perform (if the program will feel sluggish) and if it's ok that there might be a slight delay in between the (event)queued actions.

If you look at the Producer/Consumer example you'll probably get some tips on how you can split things up. Basically all work is done in the consumer and the event structure (the UI-thread) only queues commands.

In either case you'll start by queueing an Init-event, either to a queue or a user event (depending on design).

Button almost always should be placed in their respective event-case.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 13 of 19
(717 Views)

tiho wrote: I didn't understand how to separate the code between the main while loop and the other while loops.

Each instrument should have its own loop.  So each of those IMAQ references should be different loops.  That serial connection should be yet another loop.

 

This looks like it might be a good read to help you figure things out: LabVIEW Queued State Machine Architecture


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 14 of 19
(704 Views)

That's a good article CrossRulz.

Skimming through it i'd just like to add/change 2 things (mostly from a stylistic point), i dont like the "compare state to Exit", simply add an Exit state and wire True out to the Stop loop. Personally i find it abit cumbersome to remember to add Idle-state at the end of all commands, to i use the Queue timeout to go to Idle.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 15 of 19
(702 Views)

Hi

 

I have started an application using queue elements. I attatch my VI. I saw that when I push the button 2, the code of the Loop 2 is executed first and if I push the button again the code of the Loop 1 is executed. The situation is the same with the other button 1. I would like to control with the button 1 only the loop 1 and with the button 2 only the loop2.

I would like to simulate the control of two devices separated in two different loops but now with this code I can control with the buttons all loops sequentionally. I would like to check if I need this approach of programming for my application.

 

Best regards

0 Kudos
Message 16 of 19
(666 Views)

You probably need two queues, one for each consumer.

 

(Currently, both upper loops wait for a queue element, and whoever can dequeue it first (unpredictable!) will get it and the other one will get nothing. Repeat with each new queue element.)

Message 17 of 19
(657 Views)

Here's how it could be done (note that you don't need any local variables or sequence structures!)

 

 

Message 18 of 19
(640 Views)

Hi

 

I have made an application according to your suggestions and remarks. I use:

 

1. While Loop 1 with event structure.

2. While Loop 2 for control of the camera.

3. While Loop 3 for image processing.

 

The application is working but there is a small delay again between the image display from ProgResCtrl and the IMAQ Image (connected to Vision Assistant module). Than I have created one extra while loop with event structure thus separating the image processing from the normal live preview from ProgResCtrl. The situation was the same and I have corrected the application with only one while loop with event structure as at the beginning. Could you please check if the code is correct? Is It normal to have a little delay between ProgResCtrl and the IMAQ Image? I don't know how to measure the delay if you ask but the delay is visible on the screen.

 

Best regards

 

0 Kudos
Message 19 of 19
(577 Views)