08-28-2016 04:06 PM
Good day everyone.
I am having a problem with data flow between case structures.
I am trying to use a state machine example for this simple problem. but when I try to send data from one case structure to change the state of the code. It won't change to desirable output, instead it gives the option as the output from the emul options.
could someone please point out what am I doing wrong here. Any kind of help would be highly appreciated.
Solved! Go to Solution.
08-28-2016 04:14 PM
For a state machine, you'll want to make a state that checks for events rather than put everything inside the event structure.
With the two images you shared and the VI, it's rather difficult to understand exactly what you're wanting us to look at. Instead of tinkering with it for a while to determine what exactly you're doing to get to each state, why don't you give us a list of steps to run. For example:
run the vi
enter a string into this control
hit this button
view the output
Then, we're on the same page as you.
That said, I suspect your problem has to do with the output tunnels on the event structure. I notice they're all "use default if unwired." Any other event that triggers will set your value to its default (empty string, as an example).
Another problem you are likely running into... with each state being contained within the event structure, you can't transition to your second state until you fire off the same event a second time. That can't be how you want the application to run?
08-28-2016 04:29 PM
Thank you for your response.
If click the responses in this squence
Yes-->NO-->No-->Yes-->Yes-->Yes-->Yes-->Yes
The output for last case in first state (water) appears twice. while I expect it to be only once.
I believe the last thing you said about "Another problem you are likely running into... with each state being contained within the event structure, you can't transition to your second state until you fire off the same event a second time" is the exact problem I am encountering.
What can I do to deal with this problem? should I create put the event structures inside the different states or is there any other more efficient way to deal with this problem?
08-28-2016 04:47 PM
Create a case called "wait for events"
When your program is idling, send it to this state. You can use a timeout if you'd like, or leave it infinite. When you push a button to trigger a state, you transition to that state. If it requires another state, it can send the machine to that state. You can continue to do this until you want to check the events again. At this point, you go back to the wait for events state.
You currently have it built backwards.
08-28-2016 05:05 PM
08-29-2016 12:22 AM
http://www.ni.com/white-paper/3024/en/
You'd just add another case to your case structure to add another state.
I'm pretty sure there's a state machine built into the project templates if you want to see a VI.
08-29-2016 03:56 AM
I am not very familiar with state machine or event structure functions. If there's any reference vi or an example you can suggest it would be very helpful.
Thanks again for your response. I really appreciate it.
NI Example on Statemachine.....
Help----Find Examples (State)
You can Search in C:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Design Patterns\State Machine\State Machine Fundamentals.vi
08-30-2016 11:20 AM
With a quick look at your pictures one issue that you have is that you are not using data flow. You are writing your updated state value into local variables. Your state should pass through the case structures are a single wire. The read from your control "Enum" which is passed into the shift register on the right side of your loop most likely is getting executed and read before any processing occurs within your case structure. Therefore you are reading the old value of the state and not the updated one. ou have a classic case of a race condition in your code.