LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine, sub and main vi concepts

Hello 🙂

 

Main subvi is your state machine 😉 this vi will contain and call the others subvi.

 

1) sorry but i clearly not understand what you mean by "initial large block diagram"

2) well, i suppose for your application main level vi is your state machine, but this can't be true in general

3) yes state machine could be a simple vi with cases, but this depends by the complexity of your application. 

 

I've developed lots of applications using Queued state machines architecture https://decibel.ni.com/content/docs/DOC-32964 very handy, powerful and smart solution

 

0 Kudos
Message 11 of 15
(1,432 Views)
OK. I think I am getting this a bit, Remember I mentioned that I started off with a single large Vi but later realized i have to break that up into subvis since I would want to be able to return to earlier sections of code in the initial large vi. So can I confidently delete the large single vi I started off with and just use the subvis derived from it and the state machine?

[BADGE NAME]

0 Kudos
Message 12 of 15
(1,427 Views)

I suggest to do not delete the original "large" subvi, simply start a new project and reuse the subvi needed your state machine.

0 Kudos
Message 13 of 15
(1,413 Views)
OK thanks. Appreciated. I know I still have a lot of work to do in this state machine and queued message handler business 🙂

[BADGE NAME]

0 Kudos
Message 14 of 15
(1,409 Views)

I think there still may be some foggy points for you. For instance you ask something along the lines of "can't data only be sent forward?". Strictly speaking, yes, LabVIEW is a data flow language and the data flows from the beginning of a wire to the end of a wire. In a state machine, though, forward is not defined by how you named the states, but by how you call them. So you can store data in the shift register and call: state 1, state 2, state 1, state 3. And you can use that data from the shift register every time.

 

I've attached a small example that iterates on a period of 1 second just to give you a feel for what calling different states looks like. I have simple states like add and subtract so my "functions" are just the simple increment and decrement functions. Yours will be replaced by your more complicated subVIs, but the same concept applies. Normally, the "next state" you go to is determined by logic inside the case structure. In my example I put a control outside the case structure so that you can interact with it and see what happens when you change the "next state".

 

Edit: I should add that your "data" will be specific to your application. I've chosen a single integer because I just want to count up and down, but you can use strings, arrays, whatever you want. A popular choice is a cluster so that you can have several data types held in the cluster and still keep it clean with only one shift register.

 

 

Message 15 of 15
(1,402 Views)