Пример #1
0
        public void AddChannel(ScalesDescriptor sd, DbScalesMeasureData lastMeaure = null)
        {
            IScales       scales  = SetupSource(sd);
            ScalesChannel channel = null;

            if (sd.StreamType == "serial")
            {
                SerialPortSettings settings = JsonConvert.DeserializeObject <SerialPortSettings>(sd.Settings);

                channel = new ScalesChannel
                {
                    Id              = sd.Id,
                    Code            = sd.Code,
                    Name            = string.Format("{0} ({1})", sd.Name, settings.PortName),
                    Active          = scales != null ? sd.Active : false,
                    Description     = sd.Description,
                    Exposure        = TimeSpan.FromMilliseconds(sd.Exposure),
                    Timeout         = TimeSpan.FromMilliseconds(sd.Timeout),
                    TriggerEmpty    = sd.TriggerEmpty,
                    TriggerLoading  = sd.TriggerLoading,
                    ChannelSettings = settings,
                    owner           = Program.mainForm
                };
            }

            if (sd.StreamType == "tcp")
            {
                TcpChannelSettings settings = JsonConvert.DeserializeObject <TcpChannelSettings>(sd.Settings);

                channel = new ScalesChannel
                {
                    Id              = sd.Id,
                    Code            = sd.Code,
                    Name            = string.Format("{0} ({1})", "TCP", settings.Address),
                    Active          = scales != null ? sd.Active : false,
                    Description     = sd.Description,
                    Exposure        = TimeSpan.FromMilliseconds(sd.Exposure),
                    Timeout         = TimeSpan.FromMilliseconds(sd.Timeout),
                    TriggerEmpty    = sd.TriggerEmpty,
                    TriggerLoading  = sd.TriggerLoading,
                    ChannelSettings = settings,
                    owner           = Program.mainForm
                };
            }

            if (lastMeaure != null)
            {
                channel.AcceptedTime  = lastMeaure.Time;
                channel.AcceptedValue = lastMeaure.Value;
            }

            Program.MeasuringChannels.Add(channel);

            channel.EventSource = scales;
        }
Пример #2
0
        void RemoveChannel()
        {
            ScalesChannel channel = mainView.GetFocusedRow() as ScalesChannel;

            if (channel != null)
            {
                if (XtraMessageBox.Show(string.Format("Удалить канал [{0}]?", channel.Name), this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    platform.RemoveChannel(channel);
                }
            }
        }
Пример #3
0
        void ActivateChannel()
        {
            ScalesChannel channel = mainView.GetFocusedRow() as ScalesChannel;

            if (channel != null)
            {
                if (XtraMessageBox.Show(string.Format("Активизировать канал [{0}]?", channel.Name), this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    platform.ActivateChannel(channel);

                    SetupChanellCmd();
                }
            }
        }
Пример #4
0
        public void ActivateChannel(ScalesChannel channel)
        {
            if (channel != null)
            {
                using (LiteDatabase dba = new LiteDatabase(string.Format("filename={0};", Program.dbPath)))
                {
                    ScalesDescriptor sd = dba.GetCollection <ScalesDescriptor>("scales").FindById(channel.Id);
                    sd.Active = true;
                    dba.GetCollection <ScalesDescriptor>("scales").Update(sd);

                    channel.EventSource = SetupSource(sd);
                    channel.Active      = true;
                }

                LogManager.GetLogger(Application.ProductName).Info(string.Format("Активация канала {0} выполнена успешно!", channel.Name));
            }
        }
Пример #5
0
        public void DeactivateChannel(ScalesChannel channel)
        {
            if (channel != null)
            {
                var source = channel.EventSource;
                channel.EventSource = null;
                channel.Active      = false;

                using (LiteDatabase dba = new LiteDatabase(string.Format("filename={0};", Program.dbPath)))
                {
                    ScalesDescriptor sd = dba.GetCollection <ScalesDescriptor>("scales").FindById(channel.Id);
                    sd.Active = false;
                    dba.GetCollection <ScalesDescriptor>("scales").Update(sd);
                }

                if (source != null ? Program.MeasuringChannels.FirstOrDefault(tmp => tmp.EventSource == source) == null : false)
                {
                    if (source.Settings is SerialPortSettings)
                    {
                        if ((source.Settings as SerialPortSettings).PortName.StartsWith("MAN") && Program.mainForm != null)
                        {
                            var panel = Program.mainForm.dockManager.Panels.FirstOrDefault(x => Object.Equals(x.Tag, (source.Settings as SerialPortSettings).PortName));
                            if (panel != null)
                            {
                                Program.mainForm.dockManager.RemovePanel(panel);
                            }
                        }

                        LogManager.GetLogger(Application.ProductName).Info(string.Format("Остановка источника {0}", (source.Settings as SerialPortSettings).PortName));
                        source.Stop();
                        eventSource.Remove(source);
                    }

                    if (source.Settings is TcpChannelSettings)
                    {
                        LogManager.GetLogger(Application.ProductName).Info(string.Format("Остановка источника {0}", (source.Settings as TcpChannelSettings).Address));
                        source.Stop();
                        eventSource.Remove(source);
                    }


                    LogManager.GetLogger(Application.ProductName).Info(string.Format("Декативация канала {0} выполнена успешно!", channel.Name));
                }
            }
        }
Пример #6
0
        void EditChannel()
        {
            ScalesChannel channel = mainView.GetFocusedRow() as ScalesChannel;

            if (channel != null)
            {
                XChannelEdit dlg = new XChannelEdit(channel.Id);
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    Program.MeasuringChannels.Remove(channel);
                    using (LiteDatabase dba = new LiteDatabase(string.Format("filename={0};", Program.dbPath)))
                    {
                        DbScalesMeasureData lastMeaure = dba.GetCollection <DbScalesMeasureData>("measure").Find(x => x.ScalesId == dlg.ViewModel.Id).OrderByDescending(x => x.Time).FirstOrDefault();
                        platform.AddChannel(dba.GetCollection <ScalesDescriptor>("scales").FindById(dlg.ViewModel.Id), lastMeaure);
                    }
                }
            }
        }
Пример #7
0
        void SetupChanellCmd()
        {
            ScalesChannel channel = mainView.GetFocusedRow() as ScalesChannel;

            if (channel == null)
            {
                btnRemove.Enabled     = false;
                btnEdit.Enabled       = false;
                btnActivate.Enabled   = false;
                btnDeactivate.Enabled = false;
            }
            else
            {
                btnRemove.Enabled     = true;
                btnEdit.Enabled       = !channel.Active;
                btnActivate.Enabled   = !channel.Active;
                btnDeactivate.Enabled = channel.Active;
            }
        }