12-04-2012 02:38 PM
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.
Solved! Go to Solution.
12-04-2012 02:54 PM
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
12-04-2012 03:37 PM
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.
12-04-2012 05:32 PM
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.
12-04-2012 07:02 PM
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?
12-04-2012 09:46 PM - edited 12-04-2012 09:47 PM
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.
12-04-2012 10:21 PM
ah - it's the PROPERTY - that's what I was looking for thanks!
12-04-2012 10:45 PM
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.
12-04-2012 11:02 PM
Even better!
12-05-2012 12:53 PM
I tried a test on this. Maybe you can help always selects Stop for some reason and not the first letter.