diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index 1f585b6..1efb2dc 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -296,6 +296,7 @@ namespace SlnMesnac.Business tempMin = (decimal)realTemperatureInfo.fMinTemperature, tempAvg = (decimal)realTemperatureInfo.fAverageTemperature, tempDiff = (decimal)realTemperatureInfo.fTemperatureDiff, + routModel = 1, recordTime = DateTime.Now, }; diff --git a/SlnMesnac.Business/FixedPointBusiness.cs b/SlnMesnac.Business/FixedPointBusiness.cs index 7578794..dbec7ec 100644 --- a/SlnMesnac.Business/FixedPointBusiness.cs +++ b/SlnMesnac.Business/FixedPointBusiness.cs @@ -196,6 +196,7 @@ namespace SlnMesnac.Business tempMin = (decimal)realTemperatureInfo.fMinTemperature, tempAvg = (decimal)realTemperatureInfo.fAverageTemperature, tempDiff = (decimal)realTemperatureInfo.fTemperatureDiff, + routModel = 3, recordTime = DateTime.Now, }; diff --git a/SlnMesnac.Business/InspModeBusiness.cs b/SlnMesnac.Business/InspModeBusiness.cs index afe8aca..3940bb0 100644 --- a/SlnMesnac.Business/InspModeBusiness.cs +++ b/SlnMesnac.Business/InspModeBusiness.cs @@ -1,4 +1,5 @@ using SlnMesnac.Business.@base; +using SlnMesnac.Model.dto; using SlnMesnac.Plc; using SlnMesnac.Repository; using SlnMesnac.Repository.service; @@ -6,6 +7,7 @@ using SlnMesnac.Serilog; using System; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -36,24 +38,236 @@ namespace SlnMesnac.Business /// public class InspModeBusiness : BaseBusiness { + private readonly Irecord_busbar_tempServices _record_busbar_TempServices; private readonly Irecord_inspection_cabinetServices _service; - public InspModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_inspection_cabinetServices service) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices) + + public readonly RealTemperatureInfo _realTemperatureInfo = new RealTemperatureInfo(); + + public delegate void CaptureAlarmPicture(string sJpegPicFileName); + public event CaptureAlarmPicture CaptureAlarmPictureEvent; + + public delegate void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos); + public event GimbaRotationControl GimbaRotationControlEvent; + + public InspModeBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_inspection_cabinetServices service, Irecord_busbar_tempServices irecord_Busbar_TempServices) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices) { + _record_busbar_TempServices = irecord_Busbar_TempServices; _service = service; } public void Start(string taskCode,string filePath) { - record_inspection_cabinet record_Inspection = new record_inspection_cabinet(); - record_Inspection.taskCode = taskCode; - record_Inspection.filePath = filePath; - record_Inspection.beginTime = DateTime.Now; - _service.Insert(record_Inspection); + //record_inspection_cabinet record_Inspection = new record_inspection_cabinet(); + //record_Inspection.taskCode = taskCode; + //record_Inspection.filePath = filePath; + //record_Inspection.beginTime = DateTime.Now; + //_service.Insert(record_Inspection); + + InspModeEvent(); } public void Stop(string taskCode, string filePath) { } + + private void InspModeEvent() + { + try + { + Task.Run(() => + { + Task.Delay(1000).Wait(); + + base.InitEquip(1); //判断PLC状态,下发工作模式 + + int address = _plc.readInt32ByAddress("VD1100"); //读取轨道电机当前位置,判断原点及起始位置 + + //获取电柜信息 + List cabinet_Infos = new List(); + base.GetCabinetInfos(address, out cabinet_Infos); + + if (!_plc.writeInt32ByAddress("VD1516", 1)) //下发轨道电机启动信号 + { + throw new ArgumentException($"启动信号写入PLC失败;VD1516写1"); + } + + _log.Info($"启动信号写入PLC成功;VD1516写1"); + + foreach (var item in cabinet_Infos) + { + + this.SendTrackMotorAddress(item); + + if (!_plc.writeInt32ByAddress("VD1512", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 + { + throw new ArgumentException($"快速巡检下发检测完成信号写入失败;VD1512写1"); + } + Task.Delay(1000).Wait(); + } + + _log.Info($"快速巡检结束"); + }); + } + catch (Exception ex) + { + throw new InvalidOperationException($"自动巡检逻辑处理异常:{ex.Message}"); + } + } + + /// + /// 下发轨道电机位置编号 + /// + /// + /// + private void SendTrackMotorAddress(base_cabinet_info item) + { + if (!_plc.writeInt32ByAddress("VD1520", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 + { + throw new ArgumentException($"快速巡检下发轨道电机前往指定位置编号写入失败;VD1520写{item.cabinetCode}"); + } + _log.Info($"快速巡检下发轨道电机前往指定位置成功;VD1520写{item.cabinetCode}"); + + this.AwaitArriveSignal("VD1528"); //等待轨道相机到位信号 + + this.SendLiftMotorDict(item.cabinetCode); + + + } + + /// + /// 下发升降电机升降距离 + /// + /// + /// + private void SendLiftMotorDict(int cabinetCode) + { + + List busbar_Infos = new List(); + base.GetBusbarInfos(cabinetCode, out busbar_Infos); + foreach (var busbar in busbar_Infos) + { + if (!_plc.writeFloatByAddress("VD1524", ((float)busbar.busbarDist))) //下发母排距离,升降电机升降的距离 + { + throw new ArgumentException($"快速巡检下发母排升降距离写入失败;VD1524写{busbar.cabinetCode}"); + } + _log.Info($"快速巡检下发母排升降距离成功;VD1524写{busbar.busbarDist}"); + + this.AwaitArriveSignal("VD1504"); //等待升降电机到位信号 + + //控制云台旋转 + if (busbar.isRotate == 1) + { + GimbaRotationControlEvent?.Invoke(busbar.wPanPos, busbar.wTiltPos, busbar.wZoomPos); + } + + //这里采集数据 + _log.Info($"5S后开始测温"); + Task.Delay(5000).Wait(); + _log.Info($"温度测量完成,最高温度:{_realTemperatureInfo.fMaxTemperature};最低温度:{_realTemperatureInfo.fMinTemperature};平均温度:{_realTemperatureInfo.fAverageTemperature};温差:{_realTemperatureInfo.fTemperatureDiff}"); + this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo, busbar.isPictures); + Task.Delay(1000).Wait(); + + if (busbar.isRotate == 1) + { + GimbaRotationControlEvent?.Invoke("20", "4", "10"); + } + } + + } + + /// + /// 等待PLC到位信号 + /// + /// + /// + private void AwaitArriveSignal(string signal) + { + try + { + bool is_arrive = true; + while (is_arrive) + { + int is_arrive_flag = _plc.readInt32ByAddress(signal); //读取PLC轨道电机到位信号 + if (is_arrive_flag == 1) + { + _log.Info($"PLC已到达指定位置;{signal}值为{is_arrive_flag}"); + if (!_plc.writeInt32ByAddress(signal, 0)) + { + throw new ArgumentException($"PLC到位信号复位失败;{signal}写0"); + } + + is_arrive = false; + + continue; + } + + _log.Info($"等待PLC前往指定位置;{signal}值为{is_arrive_flag}"); + + Task.Delay(1000).Wait(); + } + } + catch (Exception e) + { + throw new InvalidOperationException($"等待到位信号处理异常:{e.Message}"); + } + } + + /// + /// 保存母排测温数据 + /// + /// + /// + /// + private void SaveBusbarTemp(int? busbarCode, int? cabinetCode, RealTemperatureInfo realTemperatureInfo, int isPictures) + { + try + { + + var record = new record_busbar_temp() + { + busbarCode = busbarCode, + cabinetCode = cabinetCode, + tempMax = (decimal)realTemperatureInfo.fMaxTemperature, + tempMin = (decimal)realTemperatureInfo.fMinTemperature, + tempAvg = (decimal)realTemperatureInfo.fAverageTemperature, + tempDiff = (decimal)realTemperatureInfo.fTemperatureDiff, + routModel = 2, + recordTime = DateTime.Now, + }; + + if (realTemperatureInfo.fMaxTemperature > 65) + { + record.isAlarm = 1; + string sJpegPicFileName = $"{cabinetCode}_{busbarCode}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg"; + record.filePath = sJpegPicFileName; + CaptureAlarmPictureEvent?.Invoke(sJpegPicFileName); + } + else + { + if (isPictures == 1) + { + string sJpegPicFileName = $"{cabinetCode}_{busbarCode}_{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg"; + record.filePath = sJpegPicFileName; + CaptureAlarmPictureEvent?.Invoke(sJpegPicFileName); + } + } + + var res = _record_busbar_TempServices.Insert(record); + + if (res) + { + _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存成功"); + } + else + { + _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存失败"); + } + } + catch (Exception e) + { + _log.Info($"{cabinetCode}号电柜{busbarCode}排数据保存异常:{e.Message}"); + } + } } } diff --git a/SlnMesnac.Model/domain/record_busbar_temp.cs b/SlnMesnac.Model/domain/record_busbar_temp.cs index 8925612..9239da8 100644 --- a/SlnMesnac.Model/domain/record_busbar_temp.cs +++ b/SlnMesnac.Model/domain/record_busbar_temp.cs @@ -141,5 +141,11 @@ namespace SlnMesnac.Repository [SugarColumn(ColumnName="updated_time")] public DateTime? updatedTime {get;set;} + /// + /// 巡检模式:1-自动巡检;2-快速巡检;3-定点巡检 + /// + [SugarColumn(ColumnName = "rout_model")] + public int routModel { get;set;} + } }