Think you may need to rethink your way of doing it, looks like it will be a problem to do it the way you say.
I’m assuming your setup is something like the below, if its not then please correct me.
- you have a valve that can be commanded to two positions (Open and Closed)
- you have two limit switches, one at each position, (Open limit switch and Closed limit switch)
- You want the Factory talk to display the position of the valve. (Open and Closed)
Your intended operation would be something like this:
- Start from Closed
[*]Valve is in the closed position.
[*]Closed limit switch is On.
[*]Open limit switch is Off
[*]Display state is “Valve Closed”
- Command to open
[*]Valve starts to move from Closed position to open position
[*]Closed limit switch is turn off.
[*]Open limit switch is still Off
[*]Display state remains “Valve Closed”
- Valve completes open command
[*]Valve arrives at open position
[*]Closed limit switch is still off
[*]Open Limit switch turns on
[*]Display State changes to “Valve open”
Essentially you want the display to show the position the valve last arrived at and remain in that state until the valve arrives at another position.
It is possible to set this up but I would not recommend it.
If you need to do it this way then how I would do it is to use another tag that holds the display state and have that tag set/reset or seal/unseal whenever the corresponding limit switches is turned on. Then have that tag drive the indicator.
Why it is not good: you have two limit switches that each can be two values High and low. This works out to 4 states:
State 0: Valve is in between positions
State 1: Valve is closed
State 2: Valve is open
State 3: Valve sensor is fail
In your method you are throwing away two of the states, that is good information you could have but just are throwing away.
What happens if the valve starts to slip and open a bit after closing, your display still says closed but really its partially open?
What if your limit switch gets stuck and you have them both on? Why not catch that error immediately?
cwal61 and chopin have it right, convert the sensor inputs to a dint state tag, use the states to drive the indicator.