02-17-2009 10:10 AM
In a part of my program I want to change the value of 'Boolean' depending on the value of ("K1 en K2 gesloten", this is a local variable from another part of the program). Therefore I use local variables in the True and False part of the case structures to write the value back to 'Boolean'.
If 'K1 en K2 gesloten' is true when the main program starts up, it works fine for the 'true case'. But when 'K1 en K2 gesloten' becomes false during the program, the value of 'Boolean' does not respond to the false case and Boolean holds the value from the true case.
can anyone solve this problem?
Thanks
02-17-2009 10:17 AM
02-17-2009 04:46 PM
Sam-
I'm assuming you meant to post on the LabVIEW board but missed. Either that or you got laughed off the post for having yet another local variable race condition problem. I know they can get kinda harsh about locals.
So get rid of them. use an event structure to capture value changes of 'K1 en K2 gesloten' andkick off the actions you want to happen. This is the only way to know the timing of when the event occurs. LabVIEW is a data flow control language and without an event structure you will probably never know what is occuring.
For example you read your local- then change the value. the value of the data in the wire coming from the local read is the original value and does not change. if you replace the local write ( in the other part of the program) with a property node.value(signaling) you will create an event when the value is updated.
Good luck
02-19-2009 08:03 AM
Hello Sam,
Just as Jeff is saying, my first remark is: why should you use local variables.
As I see your source code, you can do everything with direct wiring.
For example you can simply place the "Boolean" outside of the case structure.
It's very normal that during execution of your program you don't arrive in the "False" state of the case structure.
Your true case has a while loop inside it and will only go out of this loop someone clicks on the STOP2 button.
Secondly, where is "K1 & K2 gesloten" coming from?
I only can see an LED indicator representing this.
If you want to feedback a value to the left of a while loop, you can use a "shift register" instead of a local variable.
Please let us know if you need some more assistance.
I can certainly recommend you to have a look at the LabVIEW Help how "shift registers" work or as Jeff proposed using "Event Structures".
Finally can you tell me what you eventually used as reference material to start you application?
02-20-2009 02:32 PM
I'm working with local variables because if I would wire everything, my program would be a maze of wires. Are there any disadvantages with the use of local variables instead of direct wiring?
It was a stupid mistake of me to put a while loop inside the true-case. I thought the comparison functions in the true-case would only be executed one time if I did not place a while loop around it. I removed the while loop and that solved the problem (I'm only a beginner in Labview).
"K1 en K2 gesloten" is the boolean output variable coming from some logical functions (I only attached a part of my program). In the main program, 'K1 en K2 gesloten' is used to control a digital output of my NI USB 6211 device, who controls a cascade of amplifiercircuits (Darlington array, small relais) to finally control two contactors K1 and K2.
I will certainly have a look on the use of shift registers.
I assume that you mean with 'reference material' with which example I started my application?
With my application I want to measure some analog input signals, and based on the properties of them take some logical desicions and control my digital outputs. So I first searched an example VI to measure an analog input with my NI USB device and after I got this working, I added the needed logical functions, case structures, while loops, digital outputs, indicators, controls,... I used especially my basic knowledge on programming and the help functions 🙂
Best regards,
Sam
02-20-2009 03:28 PM
02-23-2009 05:06 AM
Hello Sam,
LabVIEW is a dataflow programming environment. Big advantage is that you can really "see" your data flowing through your program and follow easily it's execution.
By using local variable, you actually break the dataflow paradigm.
If you are afraid of having to much wires, you can use a "Cluster". A cluster is a collection of one or more data elements of whatever data type which are represented as one wire. Meaning, the same cluster can contain booleans, floating points, strings, ... all at once. So you actually need to use one wire for all your variables. Then you "Bundle" or "Unbundle" one or more elements at the place you need that variable. A cluster can be a control, an indicator or a constant.
Please have a look at the ZIP file I included. I used your original file you posted. I kept the logarithm, but simply used a cluser with "K1 & K2 Gesloten, Boolean and Stop Button". You will see I used an "Unbundle by Name" and "Bundle by Name" functions to read and write variables from/to the cluster.
It also contains a shift register to feedback the data to the left of the while loop each iteration.
Additionally I made from the cluster a customized control of the type "Type Def.". This is the .ctl file in the zip file. So if you need additional elements in your cluster, you can do this in this customized control. The advantage of the type "Type Def." is that all clusters used in your application based in this custom control will get update automatically with this additional element.
Save you a lot of work compared to change the clusters one by one.