Using an expression to decide states in FactoryTalk Studio ME

SiriusMark

Member
Join Date
Mar 2014
Location
Colorado
Posts
80
Hello again. I'm doing work on an HMI, trying to make it more functional. I have a button created that is intended to display whether my engine control switch is in one of four possible conditions (off, maint, auto, manual). The PLC uses four separate tags to monitor those four positions, so I need a way to incorporate all of them into one button. I tried this:

If {DieselGen\ECS_AUTO} Then STATE0 ELSE
IF {DieselGen\ECS_MAINT} then STATE1 ELSE
IF {DieselGen\ECS_MAN} THEN STATE2 ELSE
IF {DieselGen\ECS_OFF} THEN STATE3 else
state4

State 4 is just an error message. FactoryTalk accepts the syntax, but asks if I want to make STATE0-4 tags. I say no,I test the program, no workie workie.

So...how do I make the expression specifically reference the state of the button it is being created in? If ECS_Auto then this button is in state0, is basically what I want it to do.
 
Effectively what you are currently doing is setting an internal BOOL for each state detected from the plc. Instead of that, make an internal INT or DINT tag called STATE. Then say:

If {DieselGen\ECS_AUTO} Then STATE=0
ELSEIF {DieselGen\ECS_MAINT} then STATE=1
ELSEIF {DieselGen\ECS_MAN} THEN STATE=2
ELSEIF {DieselGen\ECS_OFF} THEN STATE=3
ELSE
state4

Make STATE your state control tag and set the interpretation to Value.

The easier way in my mind would be to set the value of STATE in the plc but to each his own.

Keith
 
No need to create a separate tag called eg. STATE. The following should work.

If {DieselGen\ECS_AUTO} Then 0 ELSE
IF {DieselGen\ECS_MAINT} then 1 ELSE
IF {DieselGen\ECS_MAN} THEN 2 ELSE
IF {DieselGen\ECS_OFF} THEN 3 else 4
 
Brendan's answer above is correct and the most common. The expression can only return a single value, it doesn't handle assignments since they don't return a value. Creating multiple additional tags just to represent values is rather a waste.

That said, it is much better to go with Kamanges option, and handle all of the state information in the PLC and just link that up as a single tag.
 
I went with Brendan's solution and it gave me what I needed. My mistake was in not realizing that I didn't have to identify state=0. The expression itself is created to change the state, so I don't have to refer to the state in the expression. The trick is to not try to bend the spoon, that is impossible.

Although I see the logic of using Kamanges solution, I wanted to stick with the expression option because the state tags already existed and are used elsewhere in the HMI app. This gave me the ability to write a single expression in the button properties that didn't require I make changes to the existing program. I guess it's the lazy way out, but I never denied being lazy at times. Either way, thank you all for the help, once again.
 

Similar Topics

I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
493
I'm working with Ignition 8.0.7 and am trying to enable/disable certain UDT members based on what PLC the UDT is originating from. I have a...
Replies
2
Views
2,001
Hi All, I have a nicely running process :) (knock on wood...) I have a FTStudio SE HMI and I figured out how to do many things on it including...
Replies
2
Views
2,339
Hi I'm very new to PLC programming and I'm trying to find out if this library (Tc2_NcFifoAxes) is necessary for our task In our case we need to...
Replies
0
Views
25
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
64
Back
Top Bottom