67 lines
1.3 KiB
C#
67 lines
1.3 KiB
C#
|
|
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)));
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
}
|
|
}
|
|
}
|