From acc5b2fecd8cb0ecd7e7b1365d30daffbac25368 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 21 Jul 2017 09:24:01 +0300 Subject: [PATCH] Communication with scales at the beginning (s/n, command I4) retreded 3 times. --- .../BenchControl/Sequences/MainSeq.cs | 72 +++++++++++++------ 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs index 9b67b0cd3..d1f1289d6 100644 --- a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs +++ b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs @@ -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(); + } } } }