10-05-2014 01:00 PM
@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.
10-06-2014 03:30 AM
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
10-06-2014 03:46 AM
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
10-06-2014 06:44 AM
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
10-06-2014 06:56 AM
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
10-07-2014 10:06 AM - edited 10-07-2014 10:11 AM
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
10-07-2014 10:26 AM
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.)
10-07-2014 10:55 AM
Here's how it could be done (note that you don't need any local variables or sequence structures!)
10-14-2014 05:12 AM
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