02-26-2016 09:35 AM
Hi,
I have a program with 4 different cases. I have to use the same buttons in every case. But I am not sure how to do that. When I tried to create local variable of the buttons, so as to use in all cases, an error is showing boolean latch action is incompatible with local variables. So how can I use the same buttons in 4 different cases with mechanical action latch when released. Thanking You.
02-26-2016
09:38 AM
- last edited on
07-18-2024
06:06 PM
by
Content Cleaner
The short answer: right-click the booleans and change their mechanical actions to Switching instead of Latching. This doesn't really solve your problem because this is going to introduce a bunch of race condition bugs in your code.
You don't want to split your buttons among your cases. You want a single case that handles the user events and the other cases can keep the values via shift register.
The Simple State Machine template that ships with LabVIEW is really the best way for new developers to get familiar with LabVIEW while utilizing a semi-scalable architecture.
Here's a broad example of how a state machine works:
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
02-26-2016 10:12 AM
Before we all jump to conclusions, perhaps you should share your code to show your exact situation. There is a potential for a very simple solution or it may become complex.
02-26-2016 10:32 AM
As said, I will share my code. The code is to back up data using tcp. There are mainly 4 cases all data, data younger than, data older than and defined data. I have used state machine for this I know about state machines. But then inside each case there is another state machine with 2 different cases, i.e copy and cut. For that I have used 2 buttons copy, cut and also a third button cancel, if i dont want to backup. Now this is where the problem arises. The 3 buttons I have now used in the 1st case All data, But I cant use the same in other cases. I have done things like keep the 3 buttons outside the case sturcture of the main state machine and tried to wire it into the second state machine. But that didnt work. The only way I can do it is using the 3 buttons inside the second state machine, But then I will be having this 2nd state machine in all 4 cases and I need to use the same button without chaning the mechanical action. So that is my problem. How can it be solved. Thanking You.
02-26-2016 10:41 AM - edited 02-26-2016 10:42 AM
I'm still sticking with what I said above. You shouldn't try to access the same buttons from two different places. This is especially true if you have a state machine within a state machine.
When the copy/cut/whatver button is pressed, store the values in the form of a shift register (a cluster or array of booleans) and then use the value of that shift register in the other cases if needed. YOu already know how to store the state in a shift register, so do the same with other data.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
02-26-2016 11:15 AM
Yeah, you definately should rethink your architecture. Loops inside of a state machine are generally a bad idea. And there is no reason for the block diagram to be so large (at least 4 of my screens!).
You should think about having multiple loops. One loop can be for nothing but an Event Structure to handle any button presses etc. and then another loop to handle commands coming from the event loop. Look into a Queued Message Handler to get a better idea of what I'm describing here.
02-26-2016 03:23 PM
One of the goals of using states is not to have duplicate regions of code. You violate this: earlier than, older than, all data states are identical. I see 1 parameters that differs: list of files. Make one state "process" that accepts this parameter. Define list of files in Select state and pass it through the shift register for example. Or at least make this selection in the first part of case frame that lists all three states. SubVIs to generate / read data for single file will shrink your block diagram to 800x600
Queued state machines allow you to define multiple states to run from the very beginning. (Select files, process, delete - optional)
Please check LabVIEW style book, it is much better explained there.