Exemple #1
0
        private void ReadCicle(object readOnlySelected)
        {
            ClassLog.AddLog(ELogType.Event, "ReadCicle", "ThreadRead запущен");

            while (Interlocked.CompareExchange(ref _fRead, 3, 2) == 1)
            {
                DateTime timeNext = DateTime.Now.AddMilliseconds(_readPeriod);

                ReadNet((bool)readOnlySelected);

                if (_fRead == 1)
                {
                    TimeSpan ts  = timeNext.Subtract(DateTime.Now);
                    bool     res = _autoResetReadStop.WaitOne(ts);
                    if (res)
                    {
                        Interlocked.CompareExchange(ref _fRead, 2, 1);

                        //-var flagValue = new NewChannelValue(null, DateTime.Now, NewEnumSignalStatus.FlagArchiveStop);
                        //-lock (_queueChannelValues) _queueChannelValues.Enqueue(flagValue);
                        var valueSerie = new NewChannelValueSerie(NewEnumSerieStatus.EndArchiveInterval, DateTime.Now);
                        lock (_queueCalc) _queueCalc.Enqueue(valueSerie);

                        _autoResetReadNet.Set();

                        Interlocked.CompareExchange(ref _fCalc, 2, 1);
                        _autoResetReadNet.Set();
                    }
                }
            }

            Interlocked.CompareExchange(ref _fRead, 0, 3);
            ClassLog.AddLog(ELogType.Event, "ReadCicle", "ThreadRead остановлен");
            //if (EventNetReadStop != null) EventNetReadStop(/*DateTime.Now*/);
        }
Exemple #2
0
        private void Archiver()
        {
            ClassLog.AddLog(ELogType.Event, "Archiver", "Archiver запущен");

            while (Interlocked.CompareExchange(ref _fArchive, 3, 2) == 1)
            {
                ArchiverQueue();
                if (_fArchive == 1)
                {
                    _autoResetArchive.WaitOne(ReadPeriod);
                }

                //аварийный останов, если Calc здох
                //пока не придумал как
            }

            ArchiverQueue();
            if (_fArchiveState == 1)
            {
                ClassLog.AddLog(ELogType.Event, "Archiver", "Не завершен интервал (" + _intervalId + ") архива");
            }

            Interlocked.CompareExchange(ref _fArchive, 0, 3);
            ClassLog.AddLog(ELogType.Event, "Archiver", "Archiver остановлен");
        }
Exemple #3
0
        public byte OpenPort(byte portNum, bool showAlerts = true)
        {
            var port = _hyperTerminal.OpenPort(portNum, showAlerts);

            ChangeNetType(port == 0);
            if ((portNum == 0) && (showAlerts))
            {
                MessageBox.Show(@"Виртуальный порт открыт");
            }
            ClassLog.AddLog(ELogType.Event, "ClassAdamNetReader.OpenPort",
                            (port != 0) ? "Порт " + port + " открыт" : "Виртуальный порт открыт");
            return(port);
        }
Exemple #4
0
        public void ModulesToTreeView()
        {
            if (tvModuleTree.InvokeRequired == false)
            {
                tvModuleTree.Nodes.Clear();

                foreach (NewModuleAbstract module in Program.Net.Modules)
                {
                    if (module.Address != null)
                    {
                        string nodeKey  = "M" + module.Address;
                        string nodeText = "Module " + module.Address;

                        if (!tvModuleTree.Nodes.ContainsKey(nodeKey))
                        {
                            tvModuleTree.Nodes.Add(nodeKey, nodeText);

                            foreach (NewChannelAbstract channel in module.Channels)
                            {
                                string nodeChieldKey = nodeKey + "_C" + channel.Channel;
                                nodeText = (!channel.IsCjc) ? "Channel " + channel.Channel : "CJC";
                                if (!tvModuleTree.Nodes[nodeKey].Nodes.ContainsKey(nodeChieldKey))
                                {
                                    tvModuleTree.Nodes[nodeKey].Nodes.Add(nodeChieldKey, nodeText);
                                }
                                else
                                {
                                    ClassLog.AddLog(ELogType.Event, "ClassViews.ModulesToTreeView",
                                                    "Дерево модуля уже содержит подузел "
                                                    + nodeChieldKey + " в узле " + nodeKey, DateTime.Now);
                                }
                            }
                        }
                        else
                        {
                            ClassLog.AddLog(ELogType.Event, "ClassViews.ModulesToTreeView",
                                            "Дерево модулей уже содержит узел " + nodeKey, DateTime.Now);
                        }
                    }
                }
            }
            else
            {
                var dlg = new Action(ModulesToTreeView);
                tvModuleTree.BeginInvoke(dlg);
            }
        }
Exemple #5
0
        private void butLoadConfigFromObjectsPTK_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(@"Загрузить конфигурацию каналов из TagList?", @"Загрузка конфигурации каналов", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                ClassLog.AddLog(ELogType.Event, null, "Загрузка конфигурации каналов");
                Application.DoEvents();
                _flagBlockForm = EFlagState.Yes;
                UpdateFormView();

                //ClassTagListTable.LoadChannelConfiguration(Program.Net);
                NewTagList.LoadChannelConfiguration(Program.Net);
                Program.Net.ProgramChannels();
                Program.FmMonitor.ModulesToListView();

                ClassLog.AddLog(ELogType.Event, null, "Загрузка конфигурации каналов завершена");
                _flagBlockForm = EFlagState.No;
                UpdateFormView();
            }
        }
Exemple #6
0
        public FormMonitor()
        {
            InitializeComponent();

            ClassLog.EventNewLog += AddNewLog;
            ClassLog.AddLog(ELogType.Event, null, "AuditMonitor запущен");
            NewNet.EventNetRead             += UpdateModulesValuesInListView;
            NewNet.EventNetRead             += UpdateLastReadTime;
            NewNet.EventNetReadStop         += NetReadStop;
            NewNet.EventNewModuleFind       += AddModuleToTreeView;
            NewNet.EventNewModuleFind       += AddModuleToListView;
            NewNet.EventArchiveUpdated      += UpdateArchiveSize;
            NewNet.EventConnectArchiveError += ConnectArchiveError;
            NewNet.EventWriteArchiveState   += WriteArchiveError;

            var ttErrStatus = new ToolTip {
                Active = true, AutomaticDelay = 0
            };

            ttErrStatus.SetToolTip(lvSignalList, null);
        }
Exemple #7
0
        private void Calc()
        {
            ClassLog.AddLog(ELogType.Event, "Calc", "Calc запущен");

            while (Interlocked.CompareExchange(ref _fCalc, 3, 2) == 1)
            {
                CalcQueue();
                if (_fCalc == 1)
                {
                    _autoResetReadNet.WaitOne(ReadPeriod);
                }

                //аварийный останов, если Read здох
                //пока не придумал как
            }

            CalcQueue();
            Interlocked.CompareExchange(ref _fCalc, 0, 3);
            ClassLog.AddLog(ELogType.Event, "Calc", "Calc остановлен");
            if (EventNetReadStop != null)
            {
                EventNetReadStop(/*DateTime.Now*/);
            }
        }
Exemple #8
0
        //public /*override*/ void ReadModuleOld(bool readOnlySelected = true)
        //{
        //    if (Address != null)
        //    {
        //        string stOut;
        //        string stIn;
        //        NewChannelValue signalValue;

        //        Time = DateTime.Now;

        //        //CJC
        //        if (Cjc.Selected)
        //        {
        //            stOut = "$" + Address + "3";
        //            stIn = SendCommand(stOut);

        //            if ((stIn.Length == 8) && (stIn.StartsWith(">")))
        //                signalValue = new NewChannelValue(Cjc, (DateTime)Time, stIn.Substring(1));
        //            else
        //            {
        //                ClassLog.AddLog(ELogType.ErrorModuleRead, "NewModuleAdam4019Plus.ReadModule",
        //                                "Ошибка чтения ТХС модуля " + Address, (DateTime)Time);

        //                signalValue = new NewChannelValue(Cjc, (DateTime)Time, NewEnumSignalStatus.ReadError);
        //            }
        //        }
        //        else
        //            signalValue = new NewChannelValue(Cjc, (DateTime)Time, NewEnumSignalStatus.NoRead);

        //        signalValue.CalcValue();

        //        //Channels
        //        stOut = "#" + Address;
        //        stIn = SendCommand(stOut);

        //        if ((stIn.Length == 57) && (stIn.StartsWith(">")))
        //        {
        //            //for (byte channel = 0; channel < ChannelCount; channel++)
        //            //{
        //            //    if ((!readOnlySelected) || (Channels[channel].Selected))
        //            //    {
        //            //        string signal = stIn.Substring(1 + (channel) * 7, 7);
        //            //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, signal);
        //            //    }
        //            //    else
        //            //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.NoRead);

        //            //    signalValue.CalcValue();
        //            //}

        //            foreach (NewChannelAdamAbstract channel in Channels)
        //            {
        //                if (!channel.IsCjc)
        //                {
        //                    if ((!readOnlySelected) || (channel.Selected))
        //                    {
        //                        string signal = stIn.Substring(1 + channel.Channel*7, 7);
        //                        signalValue = new NewChannelValue(channel, (DateTime) Time, signal);
        //                    }
        //                    else
        //                        signalValue = new NewChannelValue(channel, (DateTime) Time, NewEnumSignalStatus.NoRead);

        //                    signalValue.CalcValue();
        //                }
        //            }
        //        }
        //        else
        //        {
        //            ClassLog.AddLog(ELogType.ErrorModuleRead, "NewModuleAdam4019Plus.ReadModule",
        //                            "Ошибка чтения сигналов модуля " + Address, (DateTime)Time);

        //            //for (byte channel = 0; channel < ChannelCount; channel++)
        //            //{
        //            //    if ((!readOnlySelected) || (Channels[channel].Selected))
        //            //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.ReadError);
        //            //    else
        //            //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.NoRead);

        //            //    signalValue.CalcValue();
        //            //}

        //            foreach (NewChannelAdamAbstract channel in Channels)
        //            {
        //                if (!channel.IsCjc)
        //                {
        //                    if ((!readOnlySelected) || (channel.Selected))
        //                        signalValue = new NewChannelValue(channel, (DateTime)Time, NewEnumSignalStatus.ReadError);
        //                    else
        //                        signalValue = new NewChannelValue(channel, (DateTime)Time, NewEnumSignalStatus.NoRead);

        //                    signalValue.CalcValue();
        //                }
        //            }
        //        }
        //    }
        //}

        public override void ReadModule(Queue <NewChannelValue> queue, bool readOnlySelected = true)
        {
            if (Address != null)
            {
                string          stOut;
                string          stIn;
                NewChannelValue signalValue;

                Time = DateTime.Now;

                //CJC
                if ((!readOnlySelected) || (Cjc.Selected))
                {
                    stOut = "$" + Address + "3";
                    stIn  = SendCommand(stOut);

                    if ((stIn.Length == 8) && (stIn.StartsWith(">")))
                    {
                        signalValue = new NewChannelValue(Cjc, (DateTime)Time, stIn.Substring(1));
                    }
                    else
                    {
                        ClassLog.AddLog(ELogType.ErrorModuleRead, "NewModuleAdam4019Plus.ReadModule",
                                        "Ошибка чтения ТХС модуля " + Address, (DateTime)Time);

                        signalValue = new NewChannelValue(Cjc, (DateTime)Time, NewEnumSignalStatus.ReadError);
                    }
                }
                else
                {
                    signalValue = new NewChannelValue(Cjc, (DateTime)Time, NewEnumSignalStatus.NoRead);
                }

                //signalValue.CalcValue();
                lock (queue) { queue.Enqueue(signalValue); }

                //Channels
                stOut = "#" + Address;
                stIn  = SendCommand(stOut);

                if ((stIn.Length == 57) && (stIn.StartsWith(">")))
                {
                    //for (byte channel = 0; channel < ChannelCount; channel++)
                    //{
                    //    if ((!readOnlySelected) || (Channels[channel].Selected))
                    //    {
                    //        string signal = stIn.Substring(1 + (channel) * 7, 7);
                    //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, signal);
                    //    }
                    //    else
                    //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.NoRead);

                    //    //signalValue.CalcValue();
                    //    lock (queue) { Program.Net.QueueChannelValues.Enqueue(signalValue); }
                    //}

                    foreach (NewChannelAdamAbstract channel in Channels)
                    {
                        if (!channel.IsCjc)
                        {
                            if ((!readOnlySelected) || (channel.Selected))
                            {
                                string signal = stIn.Substring(1 + channel.Channel * 7, 7);
                                signalValue = new NewChannelValue(channel, (DateTime)Time, signal);
                            }
                            else
                            {
                                signalValue = new NewChannelValue(channel, (DateTime)Time, NewEnumSignalStatus.NoRead);
                            }

                            //signalValue.CalcValue();
                            lock (queue) { queue.Enqueue(signalValue); }
                        }
                    }
                }
                else
                {
                    ClassLog.AddLog(ELogType.ErrorModuleRead, "NewModuleAdam4019Plus.ReadModule",
                                    "Ошибка чтения сигналов модуля " + Address, (DateTime)Time);

                    //for (byte channel = 0; channel < ChannelCount; channel++)
                    //{
                    //    if ((!readOnlySelected) || (Channels[channel].Selected))
                    //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.ReadError);
                    //    else
                    //        signalValue = new NewChannelValue(Channels[channel], (DateTime)Time, NewEnumSignalStatus.NoRead);

                    //    //signalValue.CalcValue();
                    //    lock (queue) { Program.Net.QueueChannelValues.Enqueue(signalValue); }
                    //}

                    foreach (NewChannelAdamAbstract channel in Channels)
                    {
                        if (!channel.IsCjc)
                        {
                            if ((!readOnlySelected) || (channel.Selected))
                            {
                                signalValue = new NewChannelValue(channel, (DateTime)Time, NewEnumSignalStatus.ReadError);
                            }
                            else
                            {
                                signalValue = new NewChannelValue(channel, (DateTime)Time, NewEnumSignalStatus.NoRead);
                            }

                            //signalValue.CalcValue();
                            lock (queue) { queue.Enqueue(signalValue); }
                        }
                    }
                }
            }
        }
Exemple #9
0
        public override void ProgramModule()
        {
            if (Address != null)
            {
                //DateTime time = DateTime.Now;
                int res = 0;

                string stIn = SendCommand("$" + Address + "2");
                if (stIn.StartsWith("!" + Address) && (stIn.Length == 9))
                {
                    if (_inputRange == null)
                    {
                        InputRange = stIn.Substring(3, 2);
                    }
                    if (_baudRate == null)
                    {
                        BaudRate = stIn.Substring(5, 2);
                    }
                    if (_dataFormat == null)
                    {
                        DataFormat = stIn.Substring(7, 2);
                    }
                }

                if (stIn != "!" + Address + _inputRange + _baudRate + _dataFormat)
                {
                    stIn = SendCommand("%" + Address + Address + _inputRange + _baudRate + _dataFormat);
                    if (stIn != "!" + Address)
                    {
                        ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ProgramChannels",
                                        "Не удалось установить конфигурацию модуля " + Address + " (" + Address10 + ")",
                                        DateTime.Now);
                        res = res + 1;

                        stIn = SendCommand("$" + Address + "2");
                        if ((stIn.Length == 9) && (stIn.StartsWith("!" + Address)))
                        {
                            InputRange = stIn.Substring(3, 2);
                            BaudRate   = stIn.Substring(5, 2);
                            DataFormat = stIn.Substring(7, 2);
                        }
                        else
                        {
                            ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ProgramChannels",
                                            "Не удалось проситать конфигурацию модуля " + Address + " (" + Address10 + ")",
                                            DateTime.Now);
                            res = res + 2;

                            InputRange = null;
                            BaudRate   = null;
                            DataFormat = null;

                            foreach (NewChannelAdamAbstract channel in Channels)
                            {
                                if (!channel.IsCjc)
                                {
                                    channel.ChannelRange = null;
                                }
                            }
                        }
                    }
                }

                if ((res == 0) || (res == 1))
                {
                    foreach (NewChannelAdamAbstract channel in Channels)
                    {
                        if (!channel.IsCjc)
                        {
                            stIn = SendCommand("$" + Address + "8C" + channel.Channel);
                            if (stIn.StartsWith("!" + Address + "C" + channel.Channel + "R") && (stIn.Length == 8))
                            {
                                if (channel.ChannelRange == null)
                                {
                                    channel.ChannelRange = stIn.Substring(6, 2);
                                }
                            }

                            if (stIn != "!" + Address + "C" + channel.Channel + "R" + channel.ChannelRange)
                            {
                                stIn = SendCommand("$" + Address + "7C" + channel.Channel + "R" + channel.ChannelRange);
                                if (stIn != "!" + Address)
                                {
                                    ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ProgramChannels",
                                                    "Не удалось установить конфигурацию канала " + channel.Channel +
                                                    " модуля " + Address + " (" + Address10 + ")", DateTime.Now);

                                    stIn = SendCommand("$" + Address + "8C" + channel.Channel);
                                    if ((stIn.Length == 8) && (stIn.StartsWith("!" + Address + "C" + channel.Channel + "R")))
                                    {
                                        channel.ChannelRange = stIn.Substring(6, 2);
                                    }
                                    else
                                    {
                                        ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ProgramChannels",
                                                        "Не удалось прочитать конфигурацию канала " + channel.Channel + " модуля " +
                                                        Address + " (" + Address10 + ")", DateTime.Now);
                                        channel.ChannelRange = null;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        public override void ReadModuleSettings()
        {
            if (Address != null)
            {
                //DateTime time = DateTime.Now;

                string stIn = SendCommand("$" + Address + "2");
                if ((stIn.Length == 9) && (stIn.StartsWith("!" + Address)))
                {
                    InputRange = stIn.Substring(3, 2);
                    BaudRate   = stIn.Substring(5, 2);
                    DataFormat = stIn.Substring(7, 2);

                    foreach (NewChannelAdamAbstract channel in Channels)
                    {
                        if (!channel.IsCjc)
                        {
                            stIn = SendCommand("$" + Address + "8C" + channel.Channel);
                            if ((stIn.Length == 8) && (stIn.StartsWith("!" + Address + "C" + channel.Channel)))
                            {
                                channel.ChannelRange = stIn.Substring(6, 2);
                            }
                            else
                            {
                                ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ReadChannelsSettings",
                                                "Не удалось прочитать конфигурацию канала " + channel.Channel + " модуля " + Address
                                                + " (" + Address10 + ")", DateTime.Now);
                                channel.ChannelRange = null;
                            }
                        }
                    }
                }
                else
                {
                    ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ReadChannelsSettings",
                                    "Не удалось прочитать конфигурацию модуля " + Address + " (" + Address10 + ")"
                                    , DateTime.Now);

                    InputRange = null;
                    BaudRate   = null;
                    DataFormat = null;
                    foreach (NewChannelAdam4019Plus channel in Channels)
                    {
                        if (!channel.IsCjc)
                        {
                            channel.ChannelRange = null;
                        }
                    }
                }

                stIn = SendCommand("$" + Address + "M");
                Name = (stIn.StartsWith("!" + Address)) ? stIn.Substring(3) : null;
                if (Name == null)
                {
                    ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ReadChannelsSettings",
                                    "Не удалось прочитать имя модуля " + Address + " (" + Address10 + ")", DateTime.Now);
                }
                stIn            = SendCommand("$" + Address + "F");
                FirmwareVersion = (stIn.StartsWith("!" + Address)) ? stIn.Substring(3) : null;
                if (FirmwareVersion == null)
                {
                    ClassLog.AddLog(ELogType.ErrorModuleSettings, "NewModuleAdam4019Plus.ReadChannelsSettings",
                                    "Не удалось прочитать версию ПО модуля " + Address + " (" + Address10 + ")", DateTime.Now);
                }
            }
        }
Exemple #11
0
        //private void WriteArchiveChannel(NewChannelValue channelValue)
        //{
        //    Exception ex;

        //    if (channelValue.Channel != null)
        //    {
        //        if (_fArchiveState == 1)
        //        {
        //            Program.Archive.WriteValue(channelValue.Channel.Code, _intervalId, channelValue.CurrentValue, channelValue.Time, (byte) channelValue.Status, out ex);
        //            if (ex != null) ClassLog.AddLog(ELogType.Event, "Archive", ex.Message);
        //        }
        //    }
        //    else
        //    {
        //        if (channelValue.Status == NewEnumSignalStatus.FlagNewArchiveInterval)
        //        {
        //            bool res = Program.Archive.Connect(_archiveFileName, out ex);
        //            if(res)
        //            {
        //                res = Program.Archive.UpdateParams(Program.Net.Modules, out ex);
        //                if(res)
        //                {
        //                    _intervalId = Program.Archive.BeginInterval(channelValue.Time, null, out ex);
        //                    if (ex != null)
        //                    {
        //                        ClassLog.AddLog(ELogType.Event, null, "Ошибка при начале нового интервала архива: " + ex.Message);
        //                        res = false;
        //                    }
        //                }
        //                else
        //                    ClassLog.AddLog(ELogType.Event, null, "Ошибка при обновление списка параметров архива: " + ex.Message);
        //            }
        //            else
        //                ClassLog.AddLog(ELogType.Event, null, "Ошибка подключения к архиву: " + ex.Message);

        //            if (res)
        //                _fArchiveState = 1;
        //            else
        //            {
        //                _fArchiveState = 2;
        //                //добавить событие на ошибку записи в архив (для главной формы)
        //                ArchiveStop();
        //                if (EventConnectArchiveError != null) EventConnectArchiveError(/*DateTime.Now*/);
        //            }
        //        }
        //        else if (channelValue.Status == NewEnumSignalStatus.FlagArchiveStop)
        //        {
        //            if (_fArchiveState == 1)
        //            {
        //                Program.Archive.WriteEndIntervalValues(_intervalId, channelValue.Time, out ex);
        //                if (ex != null)
        //                    ClassLog.AddLog(ELogType.Event, null, "Ошибка при завершении значей интервала архива: " + ex.Message);
        //                Program.Archive.EndInterval(_intervalId, channelValue.Time, out ex);
        //                if (ex != null)
        //                    ClassLog.AddLog(ELogType.Event, null, "Ошибка при завершении интервала архива: " + ex.Message);
        //            }

        //            Program.Archive.Disconnect();
        //            _intervalId = -1;
        //            _fArchiveState = 0;
        //        }
        //        else if (channelValue.Status == NewEnumSignalStatus.FlagEndCicle)
        //        {
        //            if (_fArchiveState == 1)
        //            {
        //                //обновить ин-цию на форме
        //                if (EventArchiveUpdated != null) EventArchiveUpdated(Program.Archive.ValuesRecordCount);
        //            }
        //        }
        //    }
        //}

        private void ArchiverSerie(NewChannelValueSerie valueSerie)
        {
            Exception ex;
            DateTime  endTime = valueSerie.Time;

            //новый интервал
            if (valueSerie.InArchiveStatus(NewEnumSerieStatus.NewArchiveInterval))
            {
                bool res = Program.Archive.Connect(valueSerie.ArchiveFileName, out ex);
                if (res)
                {
                    res = Program.Archive.UpdateParams(Program.Net.Modules, out ex);
                    if (res)
                    {
                        _intervalId = Program.Archive.BeginInterval(valueSerie.Time, null, out ex);
                        if (ex != null)
                        {
                            ClassLog.AddLog(ELogType.Event, null, "Ошибка при начале нового интервала архива: " + ex.Message);
                            res = false;
                        }
                    }
                    else
                    {
                        ClassLog.AddLog(ELogType.Event, null, "Ошибка при обновление списка параметров архива: " + ex.Message);
                    }
                }
                else
                {
                    ClassLog.AddLog(ELogType.Event, null, "Ошибка подключения к архиву: " + ex.Message);
                }

                if (res)
                {
                    _fArchiveState = 1;
                }
                else
                {
                    _fArchiveState = 2;
                    //добавить событие на ошибку записи в архив (для главной формы)
                    ArchiveStop();
                    if (EventWriteArchiveState != null)
                    {
                        EventWriteArchiveState(true);
                    }
                    if (EventConnectArchiveError != null)
                    {
                        EventConnectArchiveError(/*DateTime.Now*/);
                    }
                }
            }

            //значения

            if (_fArchiveState == 1)
            {
                bool archiveError = false;

                while (valueSerie.QueueValues.Count > 0)
                {
                    var channelValue = valueSerie.QueueValues.Dequeue();
                    if (WriteArchiveByRead || channelValue.ValueChanged ||
                        valueSerie.InArchiveStatus(NewEnumSerieStatus.NewArchiveInterval))
                    {
                        Program.Archive.WriteValue(channelValue.Code, _intervalId, channelValue.CurrentValue,
                                                   channelValue.Time, (byte)channelValue.Status, out ex);
                        if (ex != null)
                        {
                            ClassLog.AddLog(ELogType.Event, "Archive", ex.Message);
                            archiveError = true;
                        }
                    }

                    if (channelValue.Time > endTime)
                    {
                        endTime = channelValue.Time;
                    }
                }

                if (EventWriteArchiveState != null)
                {
                    EventWriteArchiveState(archiveError);
                }
                if (EventArchiveUpdated != null)
                {
                    EventArchiveUpdated(Program.Archive.ValuesRecordCount);
                }
            }


            //конец интервала
            if (valueSerie.InArchiveStatus(NewEnumSerieStatus.EndArchiveInterval))
            {
                if (_fArchiveState == 1)
                {
                    Program.Archive.WriteEndIntervalValues(_intervalId, endTime, out ex);
                    if (ex != null)
                    {
                        ClassLog.AddLog(ELogType.Event, null, "Ошибка при завершении значей интервала архива: " + ex.Message);
                    }
                    Program.Archive.EndInterval(_intervalId, endTime, out ex);
                    if (ex != null)
                    {
                        ClassLog.AddLog(ELogType.Event, null, "Ошибка при завершении интервала архива: " + ex.Message);
                    }
                }

                Program.Archive.Disconnect();
                _intervalId    = -1;
                _fArchiveState = 0;

                if (EventWriteArchiveState != null)
                {
                    EventWriteArchiveState(false);
                }
            }
        }
Exemple #12
0
        //-private bool _fArchiveI;
        //-private bool _fLap;

        private void ReadNet(bool readOnlySelected = false)
        {
            lock (_hyperTerminal)
            {
                ClassLog.AddLog(ELogType.Event, null, "Опрос сети начат");

                //-NewChannelValue flagValue;

                ////-запись в архив: начало
                //-if(Interlocked.CompareExchange(ref _fArchiveE, 3, 1) == 1)
                //-{
                //-    flagValue = new NewChannelValue(null, DateTime.Now, NewEnumSignalStatus.FlagNewArchiveInterval);
                //-    lock (_queueChannelValues) _queueChannelValues.Enqueue(flagValue);
                //-}

                ////-опрос
                //-foreach (NewModuleAdamAbstract module in Modules)
                //-    module.ReadModule(_queueChannelValues, readOnlySelected);
                ////-lock (QueueChannelValues) QueueChannelValues.Enqueue(null);

                ////-конец цикла
                //-flagValue = new NewChannelValue(null, DateTime.Now, NewEnumSignalStatus.FlagEndCicle);
                //-_queueChannelValues.Enqueue(flagValue);

                ////-запись в архив: конец
                //-if (Interlocked.CompareExchange(ref _fArchiveE, 2, 0) == 0)
                //-{
                //-    flagValue = new NewChannelValue(null, DateTime.Now, NewEnumSignalStatus.FlagArchiveStop);
                //-    lock (_queueChannelValues) _queueChannelValues.Enqueue(flagValue);
                //-}

                var valueSerie = new NewChannelValueSerie();

                //опрос
                foreach (NewModuleAdamAbstract module in Modules)
                {
                    module.ReadModule(valueSerie.QueueValues, readOnlySelected);
                }

                //Архив
                //запись в архив: начало
                if (Interlocked.CompareExchange(ref _fArchiveE, 3, 1) == 1)
                {
                    valueSerie.ArchiveStatus  += (byte)NewEnumSerieStatus.NewArchiveInterval;
                    valueSerie.ArchiveFileName = _archiveFileName;
                }

                //запись в архив
                if (_fArchiveE == 3)
                {
                    valueSerie.ArchiveStatus += (byte)NewEnumSerieStatus.WriteArchive;
                    valueSerie.Time           = (valueSerie.QueueValues.Count > 0) ? valueSerie.QueueValues.Peek().Time  : DateTime.Now;
                }

                //запись в архив: конец
                if (Interlocked.CompareExchange(ref _fArchiveE, 0, 2) == 2)
                {
                    valueSerie.ArchiveStatus += (byte)NewEnumSerieStatus.EndArchiveInterval;
                }

                lock (_queueCalc) _queueCalc.Enqueue(valueSerie);
                _autoResetReadNet.Set();

                ClassLog.AddLog(ELogType.Event, null, "Опрос сети произведен");
            }
        }
Exemple #13
0
        public void ModulesToListView()
        {
            if (lvSignalList.InvokeRequired == false)
            {
                lvSignalList.Items.Clear();

                foreach (NewModuleAbstract module in Program.Net.Modules)
                {
                    foreach (NewChannelAbstract channel in module.Channels)
                    {
                        string itemKey  = "M" + channel.Module.Address + "C" + channel.Channel;
                        string itemText = (lvSignalList.Items.Count + 1).ToString();

                        if (!lvSignalList.Items.ContainsKey(itemKey))
                        {
                            ListViewItem curListItem = lvSignalList.Items.Add(itemKey, itemText, null);
                            curListItem.Checked = channel.Selected;
                            curListItem.SubItems.Add(channel.Code);
                            curListItem.SubItems.Add(channel.Name);
                            curListItem.SubItems.Add(channel.Signal);
                            curListItem.SubItems.Add(channel.Value.ToString());
                            curListItem.SubItems.Add(channel.Time.ToString());
                            //curListItem.SubItems.Add(((int)channel.Status).ToString());
                            curListItem.SubItems.Add((channel.Status != null) ? ((int)channel.Status).ToString() : null);
                            curListItem.SubItems.Add(channel.Module.Address10.ToString());
                            curListItem.SubItems.Add((!channel.IsCjc) ? channel.Channel.ToString() : "CJC");
                            curListItem.SubItems.Add(channel.Aperture.ToString());
                            curListItem.SubItems.Add(channel.Min.ToString());
                            curListItem.SubItems.Add(channel.Max.ToString());

                            switch (channel.ChannelType)
                            {
                            case "Adam4019+":
                                curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).DataFormat);
                                curListItem.SubItems.Add(((NewChannelAdamAbstract)channel).ChannelRange);
                                break;

                            default:
                                curListItem.SubItems.Add("");
                                curListItem.SubItems.Add("");
                                break;
                            }

                            curListItem.SubItems.Add(channel.InLevel);
                            curListItem.SubItems.Add(channel.Conversion);
                            curListItem.SubItems.Add(channel.Units);
                            curListItem.UseItemStyleForSubItems = false;
                        }
                        else
                        {
                            ClassLog.AddLog(ELogType.Event, "ClassViews.AddModuleToListView",
                                            "Элемент " + itemKey + " уже существует в списке каналов", DateTime.Now);
                            break;
                        }
                    }
                }
            }
            else
            {
                var dlg = new Action(ModulesToListView);
                lvSignalList.BeginInvoke(dlg);
            }
        }
Exemple #14
0
        private void butScanNet_Click(object sender, EventArgs e)
        {
            if (_flagBlockForm == EFlagState.No)
            {
                if (MessageBox.Show(@"Начать сканирование сети?", @"Сканирование сети", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ClassLog.AddLog(ELogType.Event, null, "Сканирование сети");

                    byte firstAddress;
                    byte lastAddress;
                    if (!byte.TryParse(tbFirstModuleAddress.Text, NumberStyles.Integer,
                                       CultureInfo.InvariantCulture.NumberFormat, out firstAddress))
                    {
                        firstAddress = 0;
                    }
                    tbFirstModuleAddress.Text = firstAddress.ToString();
                    if (!byte.TryParse(tbLastModuleAddress.Text, NumberStyles.Integer,
                                       CultureInfo.InvariantCulture.NumberFormat, out lastAddress))
                    {
                        lastAddress = 255;
                    }
                    tbLastModuleAddress.Text = lastAddress.ToString();

                    if (firstAddress > lastAddress)
                    {
                        tbLastModuleAddress.Focus();
                        MessageBox.Show(@"Кон. адрес должен быть меньше чем нач. адрес");
                        return;
                    }

                    _flagBlockForm = EFlagState.Yes;
                    UpdateFormView();
                    Program.FmMonitor.ClearModulesTreeView();
                    Program.FmMonitor.ClearSignalListView();

                    //ClassAdamNet.DelegateScanNet dlScanNet = Program.Net.ScanNet;
                    //IAsyncResult asyncResult = dlScanNet.BeginInvoke(firstAddress, lastAddress, UpdateView, null, null);
                    NewNet.DelegateScanNet dlScanNet   = Program.Net.ScanStart;
                    IAsyncResult           asyncResult = dlScanNet.BeginInvoke(firstAddress, lastAddress, UpdateView, null, null);
                    while (!asyncResult.IsCompleted)
                    {
                        Application.DoEvents();
                    }

                    tbCurModuleAddress.Text = null;

                    Program.FmMonitor.NetChange();
                    //ADAMScaner.TagListChange
                    //ADAMScaner.UpdateFormView

                    _flagBlockForm = EFlagState.No;
                    UpdateFormView();
                    ClassLog.AddLog(ELogType.Event, null, "Сканирование сети закончено");
                    MessageBox.Show(@"Сканирование сети закончено");
                }
            }
            else
            {
                Program.Net.ScanStop();
            }
        }