LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CHANGE OF STATE

Dear all,

 

I want to write an application involve change of states of an indicator.

 

 

The indicator will by default will be green in colour and will only change to to either amber or red colour.

 

I need the program to output an message only when there are certain conditions arise. The conditions are:

 

 i) green to amber

 ii) green to red

 iii) amber to red

 iv) red to amber

 

 

The rest of the conditons there will be no message output.

 

What are the best ways to write this program? Is it more efficient to use state machine, event structure for this application?

 

Anyone can help out with this? Thanks so much!

 

 

0 Kudos
Message 1 of 19
(5,192 Views)

Without knowing more about what your program is doing it's impossible to offer specific recommendations. A state machine construct is very versatile and will almost certainly work. However, keep in mind that an event structure and a state machine are not mutually exclusive. In fact, the produce-consumer architecture can be implemented this way.

 

Note that the changes in the indicator are not your real focus here. It's the condition itself. How is that generated? How did you get to the condition? The indicator changing color is just a consequence, and should have little bearing on the choice of the architecture of your code.

 

Aside: If you have not done so yet, you may want to consider using a color box for your indicator. 

Message 2 of 19
(5,168 Views)

 

Dear Sir,

 

I have already use colour code for my indicators. The indicator lights colour are determined by some numerical range of a measured quantity. Bascially i want need is monitor the change of states of the indicators. There must be a change in states in order to activate. No change in state will not be activated.

 

I am wondering whether state machine or event is more suitable?

0 Kudos
Message 3 of 19
(5,159 Views)

You need to be more specific with your question. Can you attach a simple example?

 

Can you answer all questions raised by Saverio above? 

 

What is your definition of a "message"? Is this just a string indicator or an actual popup dialog that needs to be dismissed? If you mean a string indicator, you need to define how long it should display the state change, because a nanosecond later there will again be no change, making the message disappear before it can be read by the operator.

 

Are you using a colorbox for the indicator?

 

Event structures are primarily for events triggered by user action on the front panel (with some exceptions). I assume you need to spin your loop to get the new data, so an event structure is inappropriate. You are simply looking at some real-time post-processing of the acquired data, which can be done right after the data arrives in the same code fragment.

0 Kudos
Message 4 of 19
(5,151 Views)
@ altenback... Your Crystal ball in the shop?

Paul
0 Kudos
Message 5 of 19
(5,143 Views)

Dear Sir,

 

I have written a small example on what i would like to see for the change in state. The states will be named 0,1,2 by a string indicator.

 

State 0 will be the default state and represent normal condition.

State 1 and 2 will be Abnormal state with 2 being more critical than 1.

 

Then an indicator will only be lighted up if there is a change of state from:

 

States: 0 to 1, 0 to 2, 1 to 2 and 2 to 1.                                                  -( This part i done already)

 

 

Right now my indicator will still light up for

 

States: 2 to 0 and 1 to 0 ( It should not light up as it returns to normal) - (How to solve this?)

 

The input control is a value that i obtain from one device which is polled continuouly every 1 min. 

 

This is part of my program for 1 input and there can be many inputs coming in later on (up to 50 inputs). It may get quite long and messy.

 

Therefore i want to seek your opinions on whether any other structure like state machines can simplify my application? Any elegant way of coding it?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 6 of 19
(5,122 Views)

As mentioned elsewhere, you have serious race conditions due to overuse of local variables. Reading of the NEW local will most likely occur before the code to the left of it has a change to update the value. The behavior is not predictable at all.

 

You also don't define what should happen if the input is below 0 or above 20. Since you are dealing with integers, using a string to hold the number seems unreasonable. Your case structure has no purpose and can be replaced by a green wire.

 


Joven wrote:

States: 2 to 0 and 1 to 0 ( It should not light up as it returns to normal) - (How to solve this?)


 

 You would simply do the logical OR of you "not equal" comparison and a "not equal zero" of the new value.

 

Attached is a quick simplification (LV 2009) that solves some of your missing functionality. See if it makes sense. 😉

 

Message Edited by altenbach on 04-18-2010 11:26 PM
0 Kudos
Message 7 of 19
(5,115 Views)

Dear Altenb,

 

That is indeed an elegant solution. So Short and sweet. Thanks so much for your kind help.

 

I got one a question to ask. If let say my input is an array make up of many inputs, how can i make the program shorter? I have make the vi for two inputs (as attached) but i cant imagine how big the program will be if there are more than2 inputs say maybe 10 inputs.

 

How do i write a short loop program to cater for this? How do i also create 10 boolean indicators in a group and call out the results of each boolean indicators to be used for other application?

 

Thank you so much!

0 Kudos
Message 8 of 19
(5,095 Views)

Joven wrote:

That is indeed an elegant solution. So Short and sweet. Thanks so much for your kind help.


 

 
 The program stays about the same size, even with thousands of inputs. You simply use arrays instead of scalars for the data. Infinitely scalable!
 
Here is a quick draft for 10 inputs.
 
 
 
 
(Looking at your code, you still make unnecessary local variables.  Why do you possibly need the "array" local and indicator????)
Message Edited by altenbach on 04-19-2010 07:34 AM
Download All
Message 9 of 19
(5,070 Views)

Dear Altenb,

 

Thanks so much for the help! I have tried to send the new values to activate a colour change in the respective indicators. I cant get the colour change for the first  element, the second and third indicators there are colour changes. May i seek your kind advise on this?

 

 

0 Kudos
Message 10 of 19
(5,038 Views)