(1) Prolonged method fixed, (2) UniCB simulation mode improved, ver. 3.1.1600
This commit is contained in:
@@ -180,13 +180,13 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetSetFlowArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
PID = action.PID;
|
||||
TolerRV = action.TolerRV;
|
||||
StabTime = action.StabTime;
|
||||
PID = action.PID;
|
||||
TolerRV = action.TolerRV;
|
||||
StabTime = action.StabTime;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedSetFlowArgs(Action newAction)
|
||||
@@ -219,16 +219,16 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetStartTestArgs(Action action)
|
||||
{
|
||||
FlowMId = action.FlowMId;
|
||||
DivId = action.DivId;
|
||||
DivThreshold = action.DivThreshold;
|
||||
IsSyncMethod = action.IsSyncMethod;
|
||||
IsDivUsed = action.IsDivUsed;
|
||||
IsStartStop = action.IsStartStop;
|
||||
IsProlonged = IsProlonged;
|
||||
FlowMId = action.FlowMId;
|
||||
DivId = action.DivId;
|
||||
DivThreshold = action.DivThreshold;
|
||||
IsSyncMethod = action.IsSyncMethod;
|
||||
IsDivUsed = action.IsDivUsed;
|
||||
IsStartStop = action.IsStartStop;
|
||||
IsProlonged = action.IsProlonged;
|
||||
TotalPulsesCount = action.TotalPulsesCount;
|
||||
MassPulsesCount = action.MassPulsesCount;
|
||||
StartStop = Command.Start;
|
||||
MassPulsesCount = action.MassPulsesCount;
|
||||
StartStop = Command.Start;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedStartTestArgs(Action newAction)
|
||||
@@ -278,8 +278,8 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetRegVlvIncrMoveArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
@@ -321,8 +321,8 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetRegVlvMoveToPosArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
@@ -349,8 +349,8 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetRegVlvStopArgs(Action action)
|
||||
{
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
RVMovePar2 = action.RVMovePar2;
|
||||
}
|
||||
@@ -376,8 +376,8 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
void SetSwitchDiverterArgs(Action action)
|
||||
{
|
||||
DivId = action.DivId;
|
||||
ToTank = action.ToTank;
|
||||
DivId = action.DivId;
|
||||
ToTank = action.ToTank;
|
||||
StartStop = Command.Start;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
TestWithDiverter = 0x80, /// bit 7
|
||||
/// byte 1
|
||||
TestWithRefFlowmtr = 0x100, /// bit 8
|
||||
DirectionOfDiverer = 0x200, /// bit 9
|
||||
DirectionOfDiverter= 0x200, /// bit 9
|
||||
SynchroMethod = 0x800, /// bit 11
|
||||
WaterMeterCalib = 0x1000, /// bit 12
|
||||
EmgcyStopActive = 0x2000, /// bit 13
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
|
||||
case OpState.TestPart1InProgress:
|
||||
|
||||
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
|
||||
if ((uniCB.State & (ulong)StatusP.DirectionOfDiverter) != 0)
|
||||
{
|
||||
return Event.TestPart1InProgress; /// Test was not completed yet
|
||||
}
|
||||
|
||||
@@ -234,23 +234,22 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (cbCfg.DebugLevel != DebugMode.Normal)
|
||||
lastReceivedTime = StateMachine.Time; /// To indicate the serial connection state
|
||||
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
return;
|
||||
buffer = new byte[BUFFER_SIZE];
|
||||
rcvdData = new byte[BUFFER_SIZE];
|
||||
cumulativeSums = new int[BUFFER_SIZE];
|
||||
rcvdBytesCount = 0;
|
||||
|
||||
serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
|
||||
serialPort.DtrEnable = true;
|
||||
serialPort.WriteTimeout = 4000;
|
||||
serialPort.ParityReplace = 0xFF;
|
||||
serialPort.Open();
|
||||
}
|
||||
|
||||
buffer = new byte[BUFFER_SIZE];
|
||||
rcvdData = new byte[BUFFER_SIZE];
|
||||
cumulativeSums = new int[BUFFER_SIZE];
|
||||
rcvdBytesCount = 0;
|
||||
|
||||
serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
|
||||
serialPort.DtrEnable = true;
|
||||
serialPort.WriteTimeout = 4000;
|
||||
serialPort.ParityReplace = 0xFF;
|
||||
serialPort.Open();
|
||||
|
||||
/// Handler handling mouse clicks on the schematc drawinng - valve or pump state changes
|
||||
TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args)
|
||||
{
|
||||
@@ -275,91 +274,88 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// </summary>
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (cbCfg.DebugLevel != DebugMode.Normal || serialPort == null || !serialPort.IsOpen)
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen)
|
||||
{
|
||||
benchModelRoute |= ((UInt128)1) << cbCfg.BitNr;
|
||||
return;
|
||||
}
|
||||
|
||||
/// Read new received bytes and append them to a buffer
|
||||
int bytesCount = serialPort.BytesToRead;
|
||||
if (bytesCount > 0)
|
||||
{
|
||||
bytesCount = serialPort.Read(buffer, 0, Math.Min(bytesCount, BUFFER_SIZE));
|
||||
}
|
||||
for (int i = 0; i < bytesCount && rcvdBytesCount < BUFFER_SIZE; i++, rcvdBytesCount++)
|
||||
{
|
||||
rcvdData[rcvdBytesCount] = buffer[i];
|
||||
}
|
||||
|
||||
/// Calculate cumulative sums (to verify checksums easily)
|
||||
int cumulativeSum = 0;
|
||||
for (int i = 0; i < rcvdBytesCount; i++)
|
||||
{
|
||||
cumulativeSum += rcvdData[i];
|
||||
cumulativeSums[i] = cumulativeSum;
|
||||
}
|
||||
|
||||
/// Try to detect various kinds of data in rcvdData buffer in a loop, start at offset 0
|
||||
int offset = 0;
|
||||
int lastValidOffset = 0; /// Offset of the first byte after the last successfully parsed frame
|
||||
do
|
||||
{
|
||||
bool anyProcessed = false;
|
||||
string msg = string.Empty;
|
||||
if (ScopeAnalyzerData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
/// Read new received bytes and append them to a buffer
|
||||
int bytesCount = serialPort.BytesToRead;
|
||||
if (bytesCount > 0)
|
||||
{
|
||||
/// Scope analyzer data received
|
||||
scopeAnalyzerData = ScopeAnalyzerData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Scope analyzer data ", rcvdData, offset, ScopeAnalyzerData.MessageLen);
|
||||
offset += ScopeAnalyzerData.MessageLen;
|
||||
anyProcessed = true;
|
||||
bytesCount = serialPort.Read(buffer, 0, Math.Min(bytesCount, BUFFER_SIZE));
|
||||
}
|
||||
else if (GeneralData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
for (int i = 0; i < bytesCount && rcvdBytesCount < BUFFER_SIZE; i++, rcvdBytesCount++)
|
||||
{
|
||||
/// Regular data received
|
||||
Data.UpdateData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("General data ", rcvdData, offset, GeneralData.MessageLen);
|
||||
offset += GeneralData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
else if (SwitchCountersData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Switch counter data received
|
||||
switchCounterData = SwitchCountersData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Switch counter data ", rcvdData, offset, SwitchCountersData.MessageLen);
|
||||
offset += SwitchCountersData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
else if (DivTransitionData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Diverter transition data received
|
||||
divTransitionData = DivTransitionData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Diverter transition data ", rcvdData, offset, DivTransitionData.MessageLen);
|
||||
offset += DivTransitionData.MessageLen;
|
||||
anyProcessed = true;
|
||||
rcvdData[rcvdBytesCount] = buffer[i];
|
||||
}
|
||||
|
||||
if (anyProcessed)
|
||||
/// Calculate cumulative sums (to verify checksums easily)
|
||||
int cumulativeSum = 0;
|
||||
for (int i = 0; i < rcvdBytesCount; i++)
|
||||
{
|
||||
lastValidOffset = offset;
|
||||
lastReceivedTime = StateMachine.Time;
|
||||
Debug.WriteLine(msg);
|
||||
log.Debug(msg);
|
||||
cumulativeSum += rcvdData[i];
|
||||
cumulativeSums[i] = cumulativeSum;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
while (offset < rcvdBytesCount);
|
||||
|
||||
/// Remove processed data from the receive buffer
|
||||
for (int i = lastValidOffset; i < rcvdBytesCount; i++)
|
||||
{
|
||||
rcvdData[i - lastValidOffset] = rcvdData[i];
|
||||
/// Try to detect various kinds of data in rcvdData buffer in a loop, start at offset 0
|
||||
int offset = 0;
|
||||
int lastValidOffset = 0; /// Offset of the first byte after the last successfully parsed frame
|
||||
do
|
||||
{
|
||||
bool anyProcessed = false;
|
||||
string msg = string.Empty;
|
||||
if (ScopeAnalyzerData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Scope analyzer data received
|
||||
scopeAnalyzerData = ScopeAnalyzerData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Scope analyzer data ", rcvdData, offset, ScopeAnalyzerData.MessageLen);
|
||||
offset += ScopeAnalyzerData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
else if (GeneralData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Regular data received
|
||||
Data.UpdateData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("General data ", rcvdData, offset, GeneralData.MessageLen);
|
||||
offset += GeneralData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
else if (SwitchCountersData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Switch counter data received
|
||||
switchCounterData = SwitchCountersData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Switch counter data ", rcvdData, offset, SwitchCountersData.MessageLen);
|
||||
offset += SwitchCountersData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
else if (DivTransitionData.FrameFitsData(rcvdData, cumulativeSums, rcvdBytesCount, offset))
|
||||
{
|
||||
/// Diverter transition data received
|
||||
divTransitionData = DivTransitionData.GetData(rcvdData, offset);
|
||||
msg = Telegram.LogTelegram("Diverter transition data ", rcvdData, offset, DivTransitionData.MessageLen);
|
||||
offset += DivTransitionData.MessageLen;
|
||||
anyProcessed = true;
|
||||
}
|
||||
|
||||
if (anyProcessed)
|
||||
{
|
||||
lastValidOffset = offset;
|
||||
lastReceivedTime = StateMachine.Time;
|
||||
Debug.WriteLine(msg);
|
||||
log.Debug(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
while (offset < rcvdBytesCount);
|
||||
|
||||
/// Remove processed data from the receive buffer
|
||||
for (int i = lastValidOffset; i < rcvdBytesCount; i++)
|
||||
{
|
||||
rcvdData[i - lastValidOffset] = rcvdData[i];
|
||||
}
|
||||
rcvdBytesCount -= lastValidOffset;
|
||||
}
|
||||
rcvdBytesCount -= lastValidOffset;
|
||||
|
||||
benchModelRoute = RRoute;
|
||||
///
|
||||
@@ -377,9 +373,6 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// </summary>
|
||||
public void RunDeviceAfter()
|
||||
{
|
||||
if (cbCfg.DebugLevel != DebugMode.Normal) return;
|
||||
|
||||
|
||||
/// Synchronize benchModelRoute with RRoute
|
||||
if (!IsUIBlocked && bitsChangedByUI != 0)
|
||||
{
|
||||
@@ -394,15 +387,12 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
ProcessData.AltStrings, ProcessData.Setpoints));
|
||||
|
||||
/// Make sure the serial port is open
|
||||
if (serialPort == null || !serialPort.IsOpen)
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal && (serialPort == null || !serialPort.IsOpen))
|
||||
{
|
||||
/// Serial port is closed or does not exist => re-open the serial port
|
||||
try
|
||||
{
|
||||
if (serialPort == null)
|
||||
{
|
||||
serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
|
||||
}
|
||||
if (serialPort == null) serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
|
||||
serialPort.DtrEnable = true;
|
||||
serialPort.WriteTimeout = 4000;
|
||||
serialPort.ParityReplace = 0xFF;
|
||||
@@ -453,7 +443,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
lastStateMachineTime = StateMachine.Time;
|
||||
}
|
||||
|
||||
serialPort.Write(outData, 0, outData.Length);
|
||||
if (cbCfg.DebugLevel == DebugMode.Normal) serialPort.Write(outData, 0, outData.Length);
|
||||
|
||||
string s = Telegram.LogTelegram("Sent: ", outData);
|
||||
Debug.WriteLine(s);
|
||||
|
||||
Reference in New Issue
Block a user