04-18-2010 03:06 AM
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!
04-18-2010 09:14 AM
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.
04-18-2010 12:22 PM
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?
04-18-2010 12:37 PM
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.
04-18-2010 02:26 PM
04-19-2010 12:44 AM
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?
04-19-2010 01:25 AM - edited 04-19-2010 01:26 AM
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. 😉
04-19-2010 04:52 AM
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!
04-19-2010 09:33 AM - edited 04-19-2010 09:34 AM
Joven wrote:That is indeed an elegant solution. So Short and sweet. Thanks so much for your kind help.
04-20-2010 03:44 AM
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?