Exemplo n.º 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;
        }
Exemplo n.º 2
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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void LoadMetadata()
        {
            try
            {
                LogManager.GetLogger(Application.ProductName).Info("Загрузка метаданных каналов");
                using (LiteDatabase dba = new LiteDatabase(string.Format("filename={0};", Program.dbPath)))
                {
                    foreach (var tmp in dba.GetCollection <ScalesDescriptor>("scales").FindAll())
                    {
                        LogManager.GetLogger(Application.ProductName).Info(string.Format("Загрузка настроек для {0} {1}", tmp.Name, tmp.Settings));

                        DbScalesMeasureData lastMeaure = dba.GetCollection <DbScalesMeasureData>("measure").Find(x => x.ScalesId == tmp.Id).OrderByDescending(x => x.Time).FirstOrDefault();
                        AddChannel(tmp, lastMeaure);
                    }
                }

                LogManager.GetLogger(Application.ProductName).Info("Загрузка метаданных каналов завершена");
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(Application.ProductName).Error("Ошибка загрузки метаданных", ex);
            }
        }