From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-04-2017 12:03 PM
When I enqueue the following states
stateA -> stateB -> StateC (in which stateB does stateB1->stateB2->stateB3)
I get stateA -> stateB -> StateC -> stateB1 -> stateB2 -> stateB3
How do I get stateA -> stateB -> stateB1 -> stateB2 -> stateB3 -> StateC??
If this is not possible using 'enqueue', is there other way to do this?
Solved! Go to Solution.
07-04-2017 12:16 PM
Please show is some simplified code that explains how you are doing things. It seems you just need to enqueue in the right order.
07-04-2017 01:38 PM
If your “stateB” places its actions on the front of the queue (instead of the back) then you would get the desired order.
07-04-2017 02:55 PM - edited 07-04-2017 02:55 PM
@drjdpowell wrote:
If your “stateB” places its actions on the front of the queue (instead of the back) then you would get the desired order.
True enough, but to me, that is an "emergency" condition and not a part of "normal" operations. In my opinion, if you have to regularly enqueue in the front end, you probably need to re-examine your dataflow.
07-04-2017 04:51 PM
@billko wrote:
@drjdpowell wrote:
If your “stateB” places its actions on the front of the queue (instead of the back) then you would get the desired order.
True enough, but to me, that is an "emergency" condition and not a part of "normal" operations. In my opinion, if you have to regularly enqueue in the front end, you probably need to re-examine your dataflow.
Well, if this is a message queue we’re talking about, I would re-examine any need to enqueue in front, even an “emergency”. But if the OP is instead just ordering actions internal to a loop, then I think one should ONLY “enqueue in front”, otherwise known as a “stack”.
07-04-2017 05:06 PM - edited 07-04-2017 05:07 PM
@tomsze wrote:
When I enqueue the following states
stateA -> stateB -> StateC (in which stateB does stateB1->stateB2->stateB3)
I get stateA -> stateB -> StateC -> stateB1 -> stateB2 -> stateB3
How do I get stateA -> stateB -> stateB1 -> stateB2 -> stateB3 -> StateC??
Your question really makes very little sense.
What exactly are these "states"? What do they do? What do the letters mean (e.g. how is B1 related to B or C? Is there a hierarchy somewhere)?
What prevents you from enqueuing everything in the desired final order? Is this a fixed sequence or can branching happen as a function of conditions?
07-04-2017 05:22 PM
What exactly are these "states"? What do they do? What do the letters mean (e.g. how is B1 related to B or C? Is there a hierarchy somewhere)?
There is a hierarchy. I think the OP is talking about a common LabVIEW pattern (or antipattern) of a “Queued State Machine”. A poor name, as these are usually ordering actions, not actual states. Actions can be composed of subactions.
Think subVIs. If B is a subVI called in a chain between calls to A and C, and B itself contains calls to the subsubVIs B1, B2, and B3, then the order of calling VIs is A, B, B1, B2, B3, C. When one tries to do the same things with queued actions, one instead gets A, B, C, B1, B2, B3.
07-04-2017 08:55 PM
Thanks For everyone 's reply~
I think making every states into subvi will cause me a lot of time.
Is it possible to insert state ?
07-04-2017 11:25 PM
@tomsze wrote:
Thanks For everyone 's reply~
I think making every states into subvi will cause me a lot of time.
Is it possible to insert state ?
Who knows what we are even talking about??? As far as I can see, it's just a lot of conjecture; not much more useful than gossip. We need to see code before you can receive anything more than a general answer.
07-04-2017 11:35 PM
Yes, but as people already explored above (or perhaps below, if your post order is the opposite of mine), if you're finding yourself in this position you might be better trying to avoid reaching this situation, rather than having to work around it.
As has also been described, it would be easier to give direct advice if we knew what you're using to get 'states' in an order. The most likely, as suggested by jwpowell, is that you're using a Queue with perhaps an Enum+Variant, or String+Variant, or just String/Enum as the datatype.
In this case, you can "Enqueue Element at Opposite End" to place new states at the beginning (i.e. next) in the queue. Note that you'd need to do this in reverse order:
You queue would then look like (next state bold):
But as again discussed above, usually people try to avoid using this kind of EEaOE, especially with multiple states, because it becomes more complicated to understand and debug, and can interfere with other states that expected a certain ordering, or other problems.
The JKI State Machine advocates using 'Macro' states to enqueue others - they use an array of strings as the state queue and place states at the top of the array in many cases. Some further description can be found here: JKI Best Practices, Best Practice 4: Macros. I haven't used the JKISM yet, but I have read good things about it.