Ejemplo n.º 1
0
        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);
        }