LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Momentary switches and sequential logic--- seeminly not available in Labview

I think there is a step I am missing: bringing in my subvis into the state machine frame work.

I am trying to add event case and no event sources show up.

[BADGE NAME]

0 Kudos
Message 21 of 39
(1,726 Views)

Since you've never posted your VI, it is difficult impossible to make any meaningful suggestion at this point.

 

Bob Schor

0 Kudos
Message 22 of 39
(1,719 Views)

Attached is the frame work i want to use. An event decides what the case structure executes. There is no particular sequence of states, any state change is dependent on which subvi has a value change.

 

The vi show one of the subvis i want to excecute. There is no way for me to add an event as no event source shows up. 

[BADGE NAME]

0 Kudos
Message 23 of 39
(1,715 Views)

I didn't realize how little you understand about LabVIEW (for which I apologize).

 

Create a new State Machine Template.  Go to the Wait for Event state -- this is your (only) Event Loop.  [Normally, Event Loops run in parallel with State Machines, but this is a more advanced Design Pattern, the Producer/Consumer (Events) pattern, for which there is also a Template, but let's not go there yet).

 

Before "going wild" and adding a lot of blank cases, add one Control that you want to have "trigger an Event".  Put this on your Front Panel.  On the Event Structure, add a new Event (I'd leave "Do Something" alone so you can continue to refer to it).  Modify any data you need for your State Machine as a result of clicking this control, and switch the State as shown to a new State that you will run to handle changing the control.

 

Note that the Simple State Machine uses a (fixed, but user-modifiable) Enum to hold all of the States.  If you are adding lots of States, you might find it "inconvenient" to keep modifying this Enum, and may be tempted to create a lot of badly-named Enum values such as "State 1", "State 2", etc.  If this is the case, consider making your State a String instead of an Enum.  The Advantage is you can (and should) use easily-changed mnemonic names, such as "Initialize the DAQ Device", or "Filter the Data", names that describe what the State does.  The disadvantage is that you need to get the "Spelling and Capitalization" right, as "Initialize the Daq device" won't work if the Case is named as above.  You will also need to add a Default Case, as the Case Statement has to have a "Case for Every Value", including all of the "misspellings".  [I hope you see that you can use this Default to your advantage -- if it ever "fires", then you've caught a "Programmer Spelling Error" and can stop with an appropriate Error Message].

 

Another thing you could look at, closely related to the Simple State Machine (and the "String" variant I mentioned above) is something called the Queued Message Handler.  This also has a Template, but is a bit more complicated.  It does use Strings as the "State" variable (calling it a "Message"), has a separate Error Handler (that also generates "Messages"), and uses a Producer/Consumer design to link these two parallel loops together.  This is definitely more sophisticated than the Simple State Machine, and if you decide to use this, start slowly, do one thing at a timetest your code before moving on (i.e. add one Control, run the Program, make sure it does what you expect, then add a second control).

 

Are there no LabVIEW Gurus where you are to whom you could "apprentice yourself" for a few sessions?  Spending an hour or two with someone who can explain things to you and show you some of the "errors of your ways" is not a bad way to learn.  Also spending (more) time with the Tutorials and doing all of the exercises helps.

 

Bob Schor

Message 24 of 39
(1,711 Views)
Bob,

For someone who stated using Labview for the first time ever in March, it is understandable 🙂 talking about enums I am aware that i can name them to reflect what the state does. Now the missing link in all these is that " I need to add one control that I want to trigger an event" (on the front panel of this particular "state machine vi). As obvious as that may seem I have been too fixed on thinking it would be picked up from the large vi from which I created the SubVi. This is the only phrase that bridges the gap between what I can do And can't do and my apparent gross lack of knowledge ( obviously I need to grow up like you :)) have been out of my desk for a while. Will do this once I am back and let you know how it pans out.

[BADGE NAME]

0 Kudos
Message 25 of 39
(1,694 Views)
And you know what, even before I try things out I will not hesitate to show gratitude with one kudo to your last comment. If not for anything else, that simple phrase has greatly breached that missing link. I just hope you understand how determined I am to "grow up like you" and real fast! 🙂

[BADGE NAME]

0 Kudos
Message 26 of 39
(1,684 Views)
Bob,

So far so good. My state machine has worked with the first state ( case) which executes the SubVi I sent out earlier. However I have a small issue with the next vi: I don't know how to handle refnum controls from the SubVi- how to wire the refnum inputs of this SubVi placed in my state machine. Does every terminal on the SubVi have to be wired to something in order for it to execute. I know this is what crossrulz was talking about. I could read it up in details later but right now I need a quick guide

[BADGE NAME]

0 Kudos
Message 27 of 39
(1,665 Views)

Only terminals that are marked as "required" need to be wired up in order for you VI to run.  For any terminals that aren't wired, the subVI will use whatever value you have set as default in the front panel of the subVI.

 

If you are sending in refnum's, you almost certainly want them to be wired.  If they aren't you'll probably get an invalid reference error when the subVI runs.  However, I'd question how many refnum's you need to put on the connector panel of your subVI.  You only need to send in refnums of any Main VI controls that you are going to update while the subVI is running.  Normally, you'd just pass the data out of the connector panel of the subVI and have the main VI connect that data to the terminal of the control.

Message 28 of 39
(1,645 Views)

See the Shift Register in the Example State Machine that is missing in your Maink?  It has a label "This shift register stores the data for the state machine".  This follows NI's "standard" of bundling all of the Variables used by the State Machine into a Cluster (basically a Good Idea) -- I must confess, however, that I tend to keep each variable in a Shift Register of its own, so I have a "cluster" (meaning a group of parallel wires connecting Shift Registers, not a LabVIEW Cluster) of wires at the top of my State Machine that hold the "persistent data" (or, as they are called in C, Basic, Pascal, etc., "variables") that are often passed into and out of sub-VIs (a.k.a. "functions", "procedures", "subroutines").

 

Put them back in.  Use them to pass data into and out of your sub-VIs that you are using in your various States.  Don't hesitate to show us some of these routines so we can make more helpful suggestions.  One thing that can make "showing us" easier, particularly useful if your "project" is in a LabVIEW Project (and any "LabVIEW project" worth spending more than a day's effort should be in a LabVIEW Project, a .lvproj file) is to take the folder that contains your Main and sub-VIs, compress it, and attach the single ZIP file.  This lets us see everything, including the missing sub-VIs and their dependencies.

 

Bob Schor

Message 29 of 39
(1,638 Views)

I did some troubleshooting last night and I think i can redefine this problem clearer so you can help better. I dont belieive this has to do with shift registers or my state machine. This is more of an issue with the particular subvi that wont run. (any other code i put in place of that subvi runs the state machine OK)

 

Like other subvis i created this subvi out of the large single vi i started off with. However this Subvi (prior to it creation) has a good number of property nodes which resulted in refnum inputs after creation.

Wheni tried to run the subvi standalone it gave an "object reference is invalid" error.

 

My questions now are:

 

1. How do i fix the reference error

2. How do i wire the refnum inputs on this subvi which i placed in my state machine.

 

As per the attached messag,e probes show that  Error is false just before the "str value property node" but true right after it.

[BADGE NAME]

0 Kudos
Message 30 of 39
(1,624 Views)