public override InaccuracyResult ExecuteCommand() { Result = new InaccuracyResult(); StendDLLCommands stend = new StendDLLCommands(); try { stend.SetRefClockStend(0, StendSettings.ComPort); } catch { } try { stend.ErrorClear(StendSettings.ComPort); if (StendSettings.OnePhaseTwoCircuits) { switch (IABC) { case "A": { stend.SelectCurrentCircuit(0, StendSettings.ComPort); } break; case "B": { stend.SelectCurrentCircuit(1, StendSettings.ComPort); } break; case "H": { stend.SelectCurrentCircuit(2, StendSettings.ComPort); } break; } } stend.SetReviseMode(3); stend.AdjustUI(Phase, Rated_Volt, Rated_Curr, Rated_Freq, PhaseSrequence, IsRevers, Volt_Per, Curr_Per, IABC, CosP, StendSettings.SModel, StendSettings.ComPort); for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { stend.setPulseChannel(StendSettings.ActivePlaces[j], (byte)(2 * (IsActiveEnergy == 1 ? 0 : 1) + IsRevers), StendSettings.ComPort); } if (IsActiveEnergy == 1) { StendSettings.Constant = StendSettings.ConstantAP; } else { StendSettings.Constant = StendSettings.ConstantRP; } for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { stend.errorStart(StendSettings.ActivePlaces[j], StendSettings.Constant, Impulse, StendSettings.ComPort); Result[StendSettings.ActivePlaces[j]] = ""; } Thread.Sleep(3000); while (!Cancel) { //Считываю погрешность со всех активных мест по очереди for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { //Номер посадочного места byte plaseNo = StendSettings.ActivePlaces.ElementAt(j); //Погрешность счётчика на посадочном месте string errorResultPlase = stend.ErrorRead(plaseNo, StendSettings.ComPort); if (errorResultPlase[0] != '0') { if (!Result[plaseNo].Contains(errorResultPlase.Substring(2))) { Result[plaseNo] += errorResultPlase.Substring(2) + '\n'; } } Thread.Sleep(50); } bool exit = true; int resx = 0; //Получать погрешность с счётчиков до тех пор пока все не передадут Amount измерений for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { int res = Result[StendSettings.ActivePlaces[j]].Count(x => x == '\n'); resx += res > Amount ? (int)Amount : res; exit &= res >= Amount; } Progress = ProgressMaxValue * resx / (StendSettings.ActivePlaces.Count * Amount); if (exit) { break; } } Progress = ProgressMaxValue; } catch { Progress = ProgressMinValue; throw; } finally { stend.ErrorClear(StendSettings.ComPort); stend.PowerOff(StendSettings.ComPort); } return(Result); }