10-25-2014 10:23 AM
Hi,
I build a system with a case structure that would send some command and follow them when i push a button (Changing Switch-Waiting-Flow-Waiting-Flow- Switch), but it appair that sometime, the program don't work
The problem here is the fact the program work most of the time but sometime, no. So I was wondering what could do that or what could I change to be more stable
I have join a picture of the problem area but if u find any other coding that need optimisation in my program, I would be more than happy to do the switch,
Regards,
SG
10-25-2014 11:28 AM
2MB of code? You really need to do optimization on your code. Please attach the code in 2011 version.
10-25-2014 12:42 PM
From the structure of the code it appears that you have a background in programming in a text-based language. This prevents you from taking full advantage of the power of LabVIEW.
Things to avoid:
- Local variables. Unlike text languages the variable in LV is the wire. A local variable is not a representation of the data but a remote access point to a control or indicator. Using locals is much slower than wiring, is very prone to race conditions, and creates duplicate copies of the data. For transfering data between parallel loops a queue is often the preferred choice.
- Timed loops and Timed sequence structures: These are generally for use on real-time OSes and platforms. When running on a desktop OS regular while loops are preferred. The data acquisition hardware can most likely provide adequate timing precision.
- The DAQ Assistant: This is useful for quick and dirty evaluations. For robust data acquisition processes learn to use the DAQmx VIs. This also allows you to avoid the Dynamic Data Type and all its complications. I know of no experienced LV user who likes the Dynamic Data Type.
- Very long delays: These make the program very unresponsive to the user or to errors. It is better to use a short delay and repeat it several times with checks for user input between calls to the short delay.
Fixes: Look at the Producer/Consumer Desoign Pattern or Template. All of the DAQ code can probably be in the Producer loop. All of the analysis, display, and saving to file can be in the Consumer Loop. It is possible that you may need a third loop for the PID calculations. You also need some error handling and a shutdown process to assure that the controlled system is placed into a safe state before the program exits.
And please remove the fat cat from the front panel before posting to reduce the size of the file.
Lynn
10-25-2014 12:49 PM - edited 10-25-2014 01:18 PM
You entire code is highly flawed and you are well advised to start with some tutorial before trying to attempt such a program.
My recommendation would be to take a LabVIEW course (or do all available tutorials), delete all code, retaining only the controls and indicators, then start with an established design pattern. The current code is beyond repair.
10-27-2014 08:27 AM
Thnak You for the reply !
Sorry for the cat picture, i totally forgot it,
I am putting Timed Loop because I am afraid the iteration time could variate in the process and I really need to have my data check/save every 5 minutes.
I have follow all the Labview Free Tutorial but I didn't know about the DAQ assistant or the local variable.
Thank You,
SG
10-27-2014 10:37 AM
@sillusus wrote:
- What's with all the overlapping and right-to-left wires? What do you mean by that ?
Just looking at the small section of code in the picture above, it shows very poor coding practies that make the program hard to read and understand.
Here are some examples:
10-29-2014 09:36 AM
Working on that ! Thank you !
I just have two more question at the moment (if you don't mind) :
- If I cannot use the Timed Loop or the local variable for my system, how can i use the iteration of the while loop as a one second standard ? I will just remove every local variable and every timed loop for case sequences.
- Like suggest I will convert or generate a NI DAQmx VI code/task, I just want to make sure i understand that completly, I am using a DAQ assistant for sending data to my bench, i will transform it to NI DAQmx VI task and If I am using a DAQ assistant for looking at variable from the bench, I will use a NI-DAQmx code ?
I did buy the course for Labview (Course One) for setting up my knowledge and clearing the code to be more efficient,
SG
10-29-2014 10:20 AM
With all those locals you're running into the classical problem of Race Conditions, meaning you cant tell when the locals update and which version is read. Luckily it's not a very big program so doing as Altenbach writes and start over with better understanding is the right way to go. (I got a bit scared when i saw the 2Mb size until i noticed the cat, 2Mb of code is _scary_ in a single VI)
/Y
10-29-2014 11:22 AM - edited 10-29-2014 03:44 PM
sillusus wrote:- If I cannot use the Timed Loop or the local variable for my system, how can i use the iteration of the while loop as a one second standard ?
I am not sure what you are trying to say here, but you can use anything you want. However, a well designed state machine probably does not need more than two loops (one for the UI) and probably only needs very few (maybe even zero) local variables.
@sillusus wrote:
I will just remove every local variable and every timed loop for case sequences.
What is a "case sequence"?