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); }
public override CounterResult ExecuteCommand() { Result = new CounterResult(); StendDLLCommands stend = new StendDLLCommands(); try { stend.SetRefClockStend(0, StendSettings.ComPort); //Если стенд не оборудован блоком точности хода часов } catch (StendConnectionException) { } try { stend.ErrorClear(StendSettings.ComPort); //Если стенд однофазный и у него две токовые цепи, то выбираю первую цепь (A) if (StendSettings.OnePhaseTwoCircuits) { stend.SelectCurrentCircuit(0, StendSettings.ComPort); } stend.SetReviseMode(3); //Подаю напряжение на счетчики stend.AdjustUI(Phase, Rated_Volt, 0, Rated_Freq, PhaseSrequence, IsRevers, Volt_Per, Curr_Per, IABC, CosP, StendSettings.SModel, StendSettings.ComPort); //Даю время запуститься счетчикам Thread.Sleep(5000); if (IsActiveEnergy == 1) { StendSettings.Constant = StendSettings.ConstantAP; } else { StendSettings.Constant = StendSettings.ConstantRP; } //Запускаю тест for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { stend.setPulseChannel(StendSettings.ActivePlaces[j], (byte)(2 * (IsActiveEnergy == 1 ? 0 : 1) + IsRevers), StendSettings.ComPort); stend.ConstTestStart(StendSettings.ActivePlaces[j], StendSettings.Constant, StendSettings.ComPort); } //Подаю ток, который выставлен для испытания stend.AdjustUI(Phase, Rated_Volt, Rated_Curr, Rated_Freq, PhaseSrequence, IsRevers, Volt_Per, Curr_Per, IABC, CosP, StendSettings.SModel, StendSettings.ComPort); bool[] result = new bool[StendSettings.ActivePlaces.Count]; while (!Cancel) { double count = 0; for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { if (result[j]) { continue; } stend.ConstPulseRead(out double meter_kW, out double std_kW, StendSettings.Constant, StendSettings.ActivePlaces[j], StendSettings.ComPort); //Amount тут используется как количество энергии, которое должно поступить для окончания испытаний count += std_kW > Amount ? Amount : std_kW; result[j] = std_kW >= Amount; //Высчитываю процент погрешности между энергией, которую накрутил счётчик и которую посчитал эталонный счетчик установки if (result[j]) { Result[StendSettings.ActivePlaces[j]] = string.Format("{0:f5}", (100 * (1.0 - (meter_kW / std_kW)))) + "%"; } } Progress = ProgressMaxValue * count / (Amount * StendSettings.ActivePlaces.Count); //Дожидаюсь пока получу готовность подсчета всех счетчиков bool exit = true; for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { exit &= result[j]; } if (exit) { break; } Thread.Sleep(400); } Progress = ProgressMaxValue; } catch { Progress = ProgressMinValue; throw; } finally { stend.ErrorClear(StendSettings.ComPort); stend.PowerOff(StendSettings.ComPort); } return(Result); }
public override SamohodResult ExecuteCommand() { Result = new SamohodResult(); StendDLLCommands stend = new StendDLLCommands(); try { stend.SetRefClockStend(0, StendSettings.ComPort); } catch { } try { stend.ErrorClear(StendSettings.ComPort); if (Amount < 1) { return(Result); } if (StendSettings.OnePhaseTwoCircuits) { stend.SelectCurrentCircuit(0, StendSettings.ComPort); } //Возможно она тут не обязательна 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); } for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { if (Amount == 1) { stend.searchMark(StendSettings.ActivePlaces.ElementAt(j), StendSettings.ComPort); } else { stend.CountStart(StendSettings.ActivePlaces.ElementAt(j), StendSettings.ComPort); } } Stopwatch sw = new Stopwatch(); sw.Start(); while (sw.ElapsedMilliseconds < Timeout * 1000 && !Cancel) { for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { byte idx = StendSettings.ActivePlaces.ElementAt(j); if (Amount == 1) { Result[idx] = (!stend.searchMarkResult(idx, StendSettings.ComPort)).ToString(); } else { stend.CountRead(out int result, idx, StendSettings.ComPort); Result[idx] = (result + 1 < Amount).ToString(); } } bool _stop = true; foreach (KeyValuePair <int, string> x in Result) { _stop &= !bool.Parse(x.Value); } if (_stop) { break; } Progress = ProgressMaxValue * sw.ElapsedMilliseconds / (Timeout * 1000); Thread.Sleep(400); } sw.Stop(); Progress = ProgressMaxValue; } catch { Progress = ProgressMinValue; throw; } finally { stend.ErrorClear(StendSettings.ComPort); stend.PowerOff(StendSettings.ComPort); } return(Result); }
public override ClockResult ExecuteCommand() { Result = new ClockResult(); StendDLLCommands stend = new StendDLLCommands(); try { stend.ErrorClear(StendSettings.ComPort); 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); Result[StendSettings.ActivePlaces[j]] = ""; } stend.SetRefClockStend(1, StendSettings.ComPort); for (int k = 0; k < Amount; k++) { for (int j = 0; j < StendSettings.ActivePlaces.Count; j++) { stend.ClockErrorStart(StendSettings.ActivePlaces[j], Frequency, Impulse, StendSettings.ComPort); } Stopwatch sw = new Stopwatch(); //Время одного измерения double timeMeasurement = (Frequency * Impulse + Frequency) * 1000; sw.Start(); //Для приращения прогресс бара и ожидания когда, компаратор получит все импульсы от счётчика для подсчета while (sw.ElapsedMilliseconds < (int)timeMeasurement && !Cancel) { Progress = ProgressMaxValue * (sw.ElapsedMilliseconds + timeMeasurement * k) / (int)(timeMeasurement * Amount); Thread.Sleep(100); } //Получение результатов с компаратора for (int j = 0; j < StendSettings.ActivePlaces.Count && !Cancel; j++) { string result = ""; stend.ClockErrorRead(ref result, Frequency, 0, StendSettings.ActivePlaces[j], StendSettings.ComPort); result = string.Format("{0:f7}", (double.Parse(result) - Frequency)); Result[StendSettings.ActivePlaces[j]] += result + '\n'; } } Progress = ProgressMaxValue; } catch { Progress = ProgressMinValue; throw; } finally { try { stend.ErrorClear(StendSettings.ComPort); stend.PowerOff(StendSettings.ComPort); //Если ошибка связана с COM портом, то просто игнорю т.к. первая ошибка на это укажет }catch (StendConnectionException) {} } return(Result); }