Papouch.CBoard communication change, inputs regularly read, ver. 3.1.1492

This commit is contained in:
Milan Hanajik
2020-06-14 13:04:14 +02:00
parent 1f67899a5c
commit fea7d0dc85
2 changed files with 27 additions and 6 deletions
@@ -27,6 +27,7 @@ namespace TBF.BenchControl.ControlBoard.Papouch
UInt32 currentOutputs;
bool outputsInitialized;
DateTime lastOutputsChange;
int lastStateMachineTime = 0;
///
UInt128 benchModelRoute;
UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves
@@ -119,15 +120,27 @@ namespace TBF.BenchControl.ControlBoard.Papouch
Debug.WriteLine(s);
log.Warn(s);
}
if ((telegram.Length == 6) && (telegram[1] == 0x02) && (telegram[2] == telegram.Length - 5))
{
int inputData = telegram[3];
string s = string.Format("QuidoRS inputs: {0}", inputData);
Debug.WriteLine(s);
log.Warn(s);
}
}
}
public void RunDeviceAfter()
{
if (currentOutputs != (UInt32)(benchModelRoute & 0xFFFFFFFF) || !outputsInitialized)
if (currentOutputs != (UInt32)(benchModelRoute & 0xFFFFFFFF) || !outputsInitialized || (StateMachine.Time - lastStateMachineTime) >= 3)
{
SetOutputs((UInt32)(benchModelRoute & 0xFFFFFFFF));
}
else
{
RequestInputs();
}
///
/// Collect measured values
@@ -174,8 +187,8 @@ namespace TBF.BenchControl.ControlBoard.Papouch
lock (this)
{
currentOutputs = outputs;
SendOutputs(currentOutputs);
}
SendOutputs(currentOutputs);
}
/// <summary>
@@ -188,8 +201,8 @@ namespace TBF.BenchControl.ControlBoard.Papouch
lock (this)
{
currentOutputs = currentOutputs | bitMask;
SendOutputs(currentOutputs);
}
SendOutputs(currentOutputs);
}
/// <summary>
@@ -202,8 +215,15 @@ namespace TBF.BenchControl.ControlBoard.Papouch
lock (this)
{
currentOutputs = currentOutputs & (~bitMask);
SendOutputs(currentOutputs);
}
SendOutputs(currentOutputs);
}
private void RequestInputs()
{
byte addr = cBoardCfg.ModbusAddress;
byte cmd = (byte)Function.ReadSingleInput;
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 2, 0, 0 });
}
private void SendOutputs(UInt32 outputs)
@@ -234,6 +254,7 @@ namespace TBF.BenchControl.ControlBoard.Papouch
outputsInitialized = true;
lastOutputsChange = DateTime.Now;
lastStateMachineTime = StateMachine.Time;
}