LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

programmable state machine

Solved!
Go to solution

I have a kind of display driver which at present uses a state machine and goes from A,B,C etc and cycles back to A after the entire alphabet.

I can get it to spell out words by editing the state diagram to point to whatever letter(ie state) I wish using the normal state machine method.

 

However, is there a way of prorgammably changing the state machine so I can type in say any word and it changes the next state to the required one in a general program without having to edit the state machine each time. Obviously I would need to programmably change teh next state in some way based on my data. Suppsoe I typed in the word FACE. It would then have to start at the letter F instead of A and then jump to A and C and E and then back to F again.

0 Kudos
Message 1 of 11
(3,724 Views)

Of course.  What you want is the way a state machine really works. What you described as a state machine is more of a cyclic sequencing machine.

 

Have an Idle state which waits until the word (FACE) is typed in. Then take the first letter of the string to select the next state (F). At the end of the F state, check the string.  If all the characters have been removed, then return to idle ta wait for the next string, otherwise use the next character to select the next state.

 

Lynn

0 Kudos
Message 2 of 11
(3,714 Views)

Thank you. But how do I select programmically from the enum. What I have done in the past is just manually set it and copy/paste into each state as required.

0 Kudos
Message 3 of 11
(3,700 Views)

Create a subVI which would take your letter as an input and return the value of your ENUM corresponding to that state. The BD of this VI would basically be a string input (or a U8 integer) as the case selector for a case statement containing the appropriate ENUM as the output.



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
0 Kudos
Message 4 of 11
(3,686 Views)

Yes thanks, it's not so much that which is the problem but more basic, namely how to Index (if that is the right word) an enum. So I have an enum with A,B,C,D etc in it.

In the sub if the string input is an A it sets the enum to A - but how do I do this? Is there a control input of some sort to the enum? Or do I just convert each output to a number and send that number to the enum?

0 Kudos
Message 5 of 11
(3,678 Views)

In the subVI, use the "Strings[]" property of your enum indicator (output of the subVI). Search the array for the next character in your input string, e.g., 'F'. The index returned would flow into your enum indicator. That indicator would then drive your next case.

0 Kudos
Message 6 of 11
(3,668 Views)

ah - it's the PROPERTY - that's what I was looking for thanks!

0 Kudos
Message 7 of 11
(3,662 Views)
Solution
Accepted by topic author tomnz

If your enum in fact contains {'A', 'B', 'C'...} then instead of going through the strings property to convert "F" to 'F', use the Scan Value function.  Wire an enum constant to the "default" input and set the format string to "%s".  The output value will be the corresponding enumeration value.

0 Kudos
Message 8 of 11
(3,656 Views)

Even better!

0 Kudos
Message 9 of 11
(3,650 Views)

I tried a test on this. Maybe you can help always selects Stop for some reason and not the first letter.

Download All
0 Kudos
Message 10 of 11
(3,614 Views)