示例#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}");
     }
 }
示例#2
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}初始化失败.");
         }
     }
 }
示例#3
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}");
            }

        }
示例#4
0
 public WSNSCADADasPlugin()
 {
     _log = RegisterLogDog(Title);
     LogD.Ini(_log);
     LogD.Info("Hello Plugin...");
     _service = new DasManagerService();
 }
示例#5
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);
            }
        }
示例#6
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);
        }
示例#7
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);
            }
        }
示例#8
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));
     }
 }
示例#9
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));
        }
示例#10
0
 private void Log(string content, bool isAddMonitor = true)
 {
     LogD.Info(content);
     if (isAddMonitor)
         Monitor.OnWatch(Monitor.Id, DateTime.Now.ToString(), content);
 }
示例#11
0
 private void HandleCustomCommandConfigSubstation(CustomCommandModel customCommand)
 {
     LogD.Info($"CustomCommand: 收到编辑[{customCommand.SubStationID:D3}]号分站[{customCommand.CMDData}]命令 ******");
     ConfigSubstationEvent?.Invoke(this, new ConfigSubstationEventArgs(customCommand, customCommand.SubStationID, CustomOperation.Update));
 }
示例#12
0
 public void HandleCustomCommandDeleteFlux(CustomCommandModel customCommand)
 {
     LogD.Info($"CustomCommand: 收到删除[{customCommand.CMDData:D3}]号抽采测点命令 ******");
     ConfigFluxEvent?.Invoke(this, new ConfigFluxEventArgs(customCommand, int.Parse(customCommand.CMDData), CustomOperation.Delete));
 }