Communication with scales at the beginning (s/n, command I4) retreded 3 times.

This commit is contained in:
Milan Hanajik 2017-07-21 09:24:01 +03:00
parent e76c2afa08
commit acc5b2fecd

View File

@ -135,27 +135,59 @@ namespace TBF.BenchControl.Sequences
if (getSNOp != null)
{
State.Create(string.Format("MainSeq : Reading S/N of scale {0}", scale.Name))
.AddOperation(getSNOp)
.AddOperation(new Operations.TimerOp(3))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error))
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_error));
goto error;
}
if (e.Contains(Event.TimerExpired))
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_timeout));
goto error;
}
}
while (e.Contains(Event.Busy));
const int nrRetries = 3;
if (!string.IsNullOrEmpty(sn)) log.WarnFormat("Scale {0} : s/n = {1}", scale.Name, sn);
for (int i = 1; i <= nrRetries; i++)
{
bool error = false;
bool timeout = false;
State.Create(string.Format("MainSeq : Reading S/N of scale {0} trial {1}", scale.Name, i))
.AddOperation(getSNOp)
.AddOperation(new Operations.TimerOp(2))
.EnterState();
do
{
e = StateMachine.WaitRunDevsRunOps();
if (e.Contains(Event.Error))
{
if (i == nrRetries)
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_error));
goto error;
}
else
{
error = true;
break;
}
}
if (e.Contains(Event.TimerExpired))
{
if (i == nrRetries)
{
Bridge.OnError(this, string.Format("{0} : {1}", scale.Name, Strings.Scale_communication_timeout));
goto error;
}
else
{
timeout = true;
break;
}
}
}
while (e.Contains(Event.Busy));
if (!error && !timeout)
{
/// Successful
if (!string.IsNullOrEmpty(sn)) log.WarnFormat("Scale {0} : s/n = {1}", scale.Name, sn);
break;
}
State.Create(string.Format("MainSeq : Reading S/N of scale {0}", scale.Name)).EnterState();
StateMachine.WaitRunDevsRunOps();
}
}
}
}