namespace TBF.BenchControl.Modbus.TankSelector { public class UnselectTankOp : IOperation { TankSelector tankSelector; int tankNo; ushort bitMask; bool alreadyUnselected; int time; public UnselectTankOp(TankSelector tankSelector, int tankNo) { this.tankSelector = tankSelector; this.tankNo = tankNo; this.bitMask = (ushort)((tankNo == 1) ? 8 : ((tankNo == 2) ? 0x10 : ((tankNo == 3) ? 0x20 : 0))); } /// Start this operation public void Start() { if (tankSelector.CurrentlySelectedTankValid && (tankNo == 0)) { alreadyUnselected = true; } else { tankSelector.CurrentlySelectedTank = tankNo; tankSelector.CurrentlySelectedTankValid = true; alreadyUnselected = false; time = 0; tankSelector.QuidoRS.SetBit(bitMask); } } /// Run this operation public Event Run() { if (alreadyUnselected) { return Event.ConditionMet; } else if (time == 0) { tankSelector.QuidoRS.ResetBit(bitMask); time++; return Event.ConditionNotMet; } else if (time <= 60) { time++; return Event.ConditionNotMet; } else { return Event.ConditionMet; } } /// Stop this operation public void Stop() { } } }