LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

data flow problem in case structures (using a state machine)

Solved!
Go to solution

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.

Download All
0 Kudos
Message 1 of 8
(3,461 Views)

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?

Message 2 of 8
(3,453 Views)

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?

0 Kudos
Message 3 of 8
(3,438 Views)

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.

Message 4 of 8
(3,428 Views)
I must have missed something here but how do I create a wait on event case for a state?
Basically there would only be one case at the end of every state where it would transition into a different state. Not at every case but then again since I have a string in the case as well, wouldn't that keep updating if the state is triggered while idling?

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.
0 Kudos
Message 5 of 8
(3,424 Views)

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.

Message 6 of 8
(3,375 Views)

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

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 8
(3,352 Views)
Solution
Accepted by topic author kumar1993

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 8 of 8
(3,292 Views)