Exemple #1
0
 private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     try
     {
         List <byte> listBuffer = new List <byte>();
         ReadBuffer(ref listBuffer);
         Thread.Sleep(50);
         //再次读取
         ReadBuffer(ref listBuffer);
         if (listBuffer.Any())
         {
             LogD.Info($"收到的原始报文:{ByteHelper.ToHexString(listBuffer.ToArray())}");
             var requestInfo = SubstatonFilter.Filter(listBuffer);
             if (requestInfo == null)
             {
                 IsBitError = true;
             }
             else
             {
                 IsBitError = false;
                 //触发事件
             }
             _sendCommand.IsReceiveResponse = true;
             DataReceivedEvent?.Invoke(this, new ChannelDataEventArgs(_sendCommand, requestInfo));
         }
     }
     catch (Exception ex)
     {
         _sendCommand.IsReceiveResponse = false;
         LogD.Error($"SerialPort_DataReceived:{ex}");
     }
 }
Exemple #2
0
        public Das(MonitoringServerConfigModel monitoringServerConfigModel, IEnumerable<SubStationModel> subStationModels,
            Func<string, string[], PluginMonitor> createMonitor)
        {
            try
            {
                Monitor = createMonitor(monitoringServerConfigModel.MonitoringServerID.ToString(), new string[] { "时间", "日志" });
                foreach (var substationModel in subStationModels)
                {
                    _subStationDict.TryAdd(substationModel.SubStationID, substationModel);
                }
                MonitoringServerID = monitoringServerConfigModel.MonitoringServerID;
                _serverConfig = monitoringServerConfigModel;
                var serverConfig = XmlSerializerHelper.Serializer<MonitoringServer>(monitoringServerConfigModel.Configuration);
                if (serverConfig != null)
                {

                    Comm = new Comm(serverConfig.CommunicationMode.CommMode, $"COM{serverConfig.CommunicationConfig.COM}",
                        serverConfig.CommunicationConfig.BaudRate, serverConfig.CommunicationConfig.DataBits, (StopBits)serverConfig.CommunicationConfig.StopBits,
                         serverConfig.CommunicationConfig.GetParity());
                    if (Comm != null)
                        Comm.DataReceivedEvent += Comm_DataReceivedEvent;
                }
                IsGood = true;
            }
            catch (Exception ex)
            {
                IsGood = false;
                LogD.Info($"初始化[{monitoringServerConfigModel.MonitoringServerID}]发生错误:{ex}");
            }

        }
Exemple #3
0
        private IEnumerable <IDas> InitDas()
        {
            LogD.Info("初始化数据库.");
            var monitorServerConfigModels = DasConfig.Repo.GetMonitoringServerConfigs().ToList();

            LogD.Info($"获取 Das 服务 {monitorServerConfigModels.Count}个.");

            var substationModels = DasConfig.Repo.GetSubStationModels().ToList();

            LogD.Info($"获取 分站 {substationModels.Count}个.");

            var analogPointModels = DasConfig.Repo.GetAnalogPointModels().ToList();

            LogD.Info($"获取 模拟量 {analogPointModels.Count}个.");

            var fluxPointModels = DasConfig.Repo.GetFluxPointModels().ToList();

            LogD.Info($"获取 抽采测点 {fluxPointModels.Count}个.");

            var fluxRunModels = DasConfig.Repo.GetFluxRunModels(fluxPointModels.Select(p => p.FluxID).ToArray());

            LogD.Info($"获取 抽采测点当前记录 {fluxPointModels.Count}个.");

            InitTreeStructure(monitorServerConfigModels, substationModels, analogPointModels, fluxPointModels, fluxRunModels);
            var dass = new List <IDas>();

            foreach (var item in monitorServerConfigModels)
            {
                var das = NewDas(item, item.SubStationModels);
                yield return(das);
            }
        }
Exemple #4
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                CultureInfoHelper.SetDateTimeFormat();
                while (!_cts.IsCancellationRequested)
                {
                    // das 循环发送命令, 并接受报文.
                    try
                    {
                        //if (Comm == null || !Comm.IsConnect)
                        //{
                        //    Log($"网络断开,{Comm}重新连接.");
                        //    Comm?.Start();
                        //    Thread.Sleep(3000);
                        //    continue;
                        //}
                        GatherData();

                    }
                    catch (Exception e)
                    {
                        LogD.Error("轮询中出现错误:" + e);
                    }
                    finally
                    {
                        Thread.Sleep(50);
                    }
                }

            }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Exemple #5
0
 public WSNSCADADasPlugin()
 {
     _log = RegisterLogDog(Title);
     LogD.Ini(_log);
     LogD.Info("Hello Plugin...");
     _service = new DasManagerService();
 }
Exemple #6
0
        public void Start(PluginMonitor databaseMonitor, PluginMonitor dasMonitor)
        {
            try
            {
#if DEBUG
                var hexString      = "01 03 1E 00 00 00 00 00 00 00 00 42 C7 D0 13 00 00 41 D0 0A F1 00 00 41 EA 80 00 00 00 41 EE CF 38 6F 91";
                var bytes          = ByteHelper.HexStringToByteArray(hexString);
                var substationData = new SubStationData(1, bytes.Skip(3).Take(0x1E).ToArray());
#endif
                _databaseMonitor = databaseMonitor;
                _dasMonitor      = dasMonitor;
                _dases.AddRange(InitDas());
                _dases.ToList().ForEach(o => o.Start());
                _customCommandService.Start();
                _customCommandService.ConfigMonitoringServerEvent += CustomCommandService_ConfigMonitoringServerEvent;
                _customCommandService.ConfigSubstationEvent       += CustomCommandService_ConfigSubstationEvent;
                _customCommandService.ConfigFluxEvent             += CustomCommandService_ConfigFluxEvent;
                _dataBulkService.Start(_databaseMonitor);
                DasConfig.Repo.EndAlarmToday();
                DasConfig.Repo.EndAnalogAlarm();
            }
            catch (Exception ex)
            {
                LogD.Error(ex.ToString());
            }
        }
Exemple #7
0
 private void AddDas(int dasId)
 {
     if (!_dases.Exists(p => p.MonitoringServerID == dasId))
     {
         var monitorServerConfig = DasConfig.Repo.GetMonitoringServerConfigModelById(dasId);
         var substationModels    = DasConfig.Repo.GetSubStationModelsByMonitorServerId(dasId).ToList();
         var analogPointModels   = DasConfig.Repo.GetAnalogPointModels();
         var fluxPointModels     = DasConfig.Repo.GetFluxPointModels();
         var fluxRunModels       = DasConfig.Repo.GetFluxRunModels(fluxPointModels.Select(p => p.FluxID).ToArray());
         foreach (var substation in substationModels)
         {
             var subAnalogPointModels = analogPointModels.Where(p => p.SubStationID == substation.SubStationID).ToList();
             var subFluxPointModels   = fluxPointModels.Where(p => p.SubStationID == substation.SubStationID).ToList();
             var subFluxRunModels     = fluxRunModels.Where(p => p.SubStationID == substation.SubStationID).ToList();
             substation.InitPointModel(subAnalogPointModels, subFluxPointModels, subFluxRunModels);
         }
         var dasSubstationModels = substationModels.Where(p => p.MonitoringServerID == monitorServerConfig.MonitoringServerID).ToList();
         monitorServerConfig.InitSubStation(dasSubstationModels);
         var newDas = NewDas(monitorServerConfig, substationModels);
         if (newDas.IsGood)
         {
             _dases.Add(newDas);
             newDas.Start();
         }
         else
         {
             LogD.Info($"采集服务器{dasId}初始化失败.");
         }
     }
 }
Exemple #8
0
        private IDas NewDas(MonitoringServerConfigModel monitoringServerConfigModel, List <SubStationModel> subStationModels)
        {
            var das = new Das(monitoringServerConfigModel, subStationModels, CreateDasLogMonitor);

            LogD.Info($"初始化  采集服务器 {monitoringServerConfigModel.MonitoringServerID}.");
            das.DasUpdateRealData += _dataBulkService.DasUpdateRealData;
            return(das);
        }
Exemple #9
0
        private void RemoveDas(int dasId)
        {
            var das = _dases.Find(o => o.MonitoringServerID == dasId);

            if (das != null)
            {
                das.DasUpdateRealData -= _dataBulkService.DasUpdateRealData;
                das.Stop();
                LogD.Info($"移除旧的 采集 {dasId}.");
                _dases.Remove(das);
            }
        }
Exemple #10
0
 private void HandleCustomCommandConfigFlux(CustomCommandModel customCommand)
 {
     LogD.Info($"CustomCommand: 收到编辑[{customCommand.CMDData:D3}]号抽采测点命令 ******");
     if (string.IsNullOrEmpty(customCommand.CMDData))
     {
         customCommand.Finish();
     }
     else
     {
         ConfigFluxEvent?.Invoke(this, new ConfigFluxEventArgs(customCommand, int.Parse(customCommand.CMDData), CustomOperation.Update));
     }
 }
Exemple #11
0
 public void Stop()
 {
     try
     {
         _dases.ForEach(o => o.Stop());
         _dataBulkService.Stop();
         _customCommandService.Stop();
         _customCommandService.ConfigMonitoringServerEvent -= CustomCommandService_ConfigMonitoringServerEvent;
         _customCommandService.ConfigSubstationEvent       -= CustomCommandService_ConfigSubstationEvent;
         _customCommandService.ConfigFluxEvent             -= CustomCommandService_ConfigFluxEvent;
     }
     catch (Exception ex)
     {
         LogD.Error(ex.ToString());
     }
 }
Exemple #12
0
        public void Stop()
        {

            try
            {
                _cts.Cancel();
                if (Comm != null)
                {
                    Comm.DataReceivedEvent -= Comm_DataReceivedEvent;
                    Comm.Close();
                }
            }
            catch (Exception ex)
            {
                LogD.Error(ex.ToString());
            }
        }
Exemple #13
0
        private void HandleCustomCommandConfigServer(CustomCommandModel customCommand)
        {
            LogD.Info($"CustomCommand: 收到编辑[{customCommand.MonitoringServerID:D3}]号采集服务器[{customCommand.CMDData}]命令 ******");
            CustomOperation operation;

            if (customCommand.CMDData == "add")
            {
                operation = CustomOperation.Add;
            }
            else if (customCommand.CMDData == "delete")
            {
                operation = CustomOperation.Delete;
            }
            else
            {
                operation = CustomOperation.Update;
            }
            ConfigMonitoringServerEvent?.Invoke(this, new ConfigMonitoringServerEventArgs(customCommand, customCommand.MonitoringServerID, operation));
        }
Exemple #14
0
 private void Log(string content, bool isAddMonitor = true)
 {
     LogD.Info(content);
     if (isAddMonitor)
         Monitor.OnWatch(Monitor.Id, DateTime.Now.ToString(), content);
 }
Exemple #15
0
 private void HandleCustomCommandConfigSubstation(CustomCommandModel customCommand)
 {
     LogD.Info($"CustomCommand: 收到编辑[{customCommand.SubStationID:D3}]号分站[{customCommand.CMDData}]命令 ******");
     ConfigSubstationEvent?.Invoke(this, new ConfigSubstationEventArgs(customCommand, customCommand.SubStationID, CustomOperation.Update));
 }
Exemple #16
0
 public void HandleCustomCommandDeleteFlux(CustomCommandModel customCommand)
 {
     LogD.Info($"CustomCommand: 收到删除[{customCommand.CMDData:D3}]号抽采测点命令 ******");
     ConfigFluxEvent?.Invoke(this, new ConfigFluxEventArgs(customCommand, int.Parse(customCommand.CMDData), CustomOperation.Delete));
 }