From 66922f3f30270e1a59be3a1a0d38d55dfc54f8f3 Mon Sep 17 00:00:00 2001 From: wenjy Date: Fri, 29 Nov 2024 13:43:05 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E6=B7=BB=E5=8A=A0=E5=AE=9A?= =?UTF-8?q?=E7=82=B9=E5=B7=A1=E6=A3=80=EF=BC=8C=E6=9B=BF=E6=8D=A2PLC?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/AutoModeBusiness.cs | 38 ++-- SlnMesnac.Business/FixedPointBusiness.cs | 170 ++++++++++++++++++ SlnMesnac.Business/base/BaseBusiness.cs | 10 +- SlnMesnac.WPF/Page/FixedPointWindow.xaml | 51 ++++++ SlnMesnac.WPF/Page/FixedPointWindow.xaml.cs | 32 ++++ SlnMesnac.WPF/Page/IndexControl.xaml.cs | 153 ++++++++++++---- .../ViewModel/FixedPointViewModel.cs | 87 +++++++++ .../ViewModel/IndexControlViewModel.cs | 3 + SlnMesnac.WPF/appsettings.json | 2 +- 9 files changed, 487 insertions(+), 59 deletions(-) create mode 100644 SlnMesnac.Business/FixedPointBusiness.cs create mode 100644 SlnMesnac.WPF/Page/FixedPointWindow.xaml create mode 100644 SlnMesnac.WPF/Page/FixedPointWindow.xaml.cs create mode 100644 SlnMesnac.WPF/ViewModel/FixedPointViewModel.cs diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index defc01f..1f585b6 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -143,21 +143,21 @@ namespace SlnMesnac.Business List cabinet_Infos = new List(); base.GetCabinetInfos(address, out cabinet_Infos); - if (!_plc.writeInt32ByAddress("VD1517", 1)) //下发轨道电机启动信号 + if (!_plc.writeInt32ByAddress("VD1516", 1)) //下发轨道电机启动信号 { - throw new ArgumentException($"启动信号写入PLC失败;VD1517写1"); + throw new ArgumentException($"启动信号写入PLC失败;VD1516写1"); } - _log.Info($"启动信号写入PLC成功;VD1517写1"); + _log.Info($"启动信号写入PLC成功;VD1516写1"); foreach (var item in cabinet_Infos) { this.SendTrackMotorAddress(item); - if (!_plc.writeInt32ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 + if (!_plc.writeInt32ByAddress("VD1512", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 { - throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败;VD1513写1"); + throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败;VD1512写1"); } Task.Delay(1000).Wait(); } @@ -177,19 +177,19 @@ namespace SlnMesnac.Business /// private void SendTrackMotorAddress(base_cabinet_info item) { - if (!_plc.writeInt32ByAddress("VD1521", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 + if (!_plc.writeInt32ByAddress("VD1520", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 { - throw new ArgumentException($"下发轨道电机前往指定位置编号写入失败;VD1521写{item.cabinetCode}"); + throw new ArgumentException($"下发轨道电机前往指定位置编号写入失败;VD1520写{item.cabinetCode}"); } - _log.Info($"下发轨道电机前往指定位置成功;VD1521写{item.cabinetCode}"); + _log.Info($"下发轨道电机前往指定位置成功;VD1520写{item.cabinetCode}"); - this.AwaitArriveSignal("VD1529"); //等待轨道相机到位信号 + this.AwaitArriveSignal("VD1528"); //等待轨道相机到位信号 this.SendLiftMotorDict(item.cabinetCode); - //if (!_plc.writeInt32ByAddress("VD1521", 0)) + //if (!_plc.writeInt32ByAddress("VD1520", 0)) //{ - // throw new ArgumentException($"电柜检测完成轨道电机地址写0失败;VD1521写0"); + // throw new ArgumentException($"电柜检测完成轨道电机地址写0失败;VD1520写0"); //} } @@ -206,13 +206,13 @@ namespace SlnMesnac.Business base.GetBusbarInfos(cabinetCode, out busbar_Infos); foreach (var busbar in busbar_Infos) { - if (!_plc.writeFloatByAddress("VD1525", ((float)busbar.busbarDist))) //下发母排距离,升降电机升降的距离 + if (!_plc.writeFloatByAddress("VD1524", ((float)busbar.busbarDist))) //下发母排距离,升降电机升降的距离 { - throw new ArgumentException($"下发母排升降距离写入失败;VD1525写{busbar.cabinetCode}"); + throw new ArgumentException($"下发母排升降距离写入失败;VD1524写{busbar.cabinetCode}"); } - _log.Info($"下发母排升降距离成功;VD1525写{busbar.busbarDist}"); + _log.Info($"下发母排升降距离成功;VD1524写{busbar.busbarDist}"); - this.AwaitArriveSignal("VD1505"); //等待升降电机到位信号 + this.AwaitArriveSignal("VD1504"); //等待升降电机到位信号 //控制云台旋转 if(busbar.isRotate == 1) @@ -227,11 +227,11 @@ namespace SlnMesnac.Business this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo,busbar.isPictures); Task.Delay(1000).Wait(); - //if (!_plc.writeFloatByAddress("VD1525", 0)) + //if (!_plc.writeFloatByAddress("VD1524", 0)) //{ - // throw new ArgumentException($"母排检测完成向PLC升降距离写0失败;VD1525写0"); + // throw new ArgumentException($"母排检测完成向PLC升降距离写0失败;VD1524写0"); //} - //_log.Info($"母排检测完成向PLC升降距离写0成功;VD1525写0"); + //_log.Info($"母排检测完成向PLC升降距离写0成功;VD1524写0"); if(busbar.isRotate == 1) { @@ -348,7 +348,7 @@ namespace SlnMesnac.Business public string GetDeviceStatus() { - int deviceStatus = _plc.readInt32ByAddress("VD1509"); + int deviceStatus = _plc.readInt32ByAddress("VD1508"); string deviceStatusFlag = string.Empty; diff --git a/SlnMesnac.Business/FixedPointBusiness.cs b/SlnMesnac.Business/FixedPointBusiness.cs new file mode 100644 index 0000000..acd218f --- /dev/null +++ b/SlnMesnac.Business/FixedPointBusiness.cs @@ -0,0 +1,170 @@ +using SlnMesnac.Business.@base; +using SlnMesnac.Model.dto; +using SlnMesnac.Plc; +using SlnMesnac.Repository; +using SlnMesnac.Repository.service; +using SlnMesnac.Serilog; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +#region << 版 本 注 释 >> +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:T14-GEN3-7895 +* 命名空间:SlnMesnac.Business +* 唯一标识:2202e7a9-f41e-4b59-b139-05f10987e114 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2024-11-29 10:58:14 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ +#endregion << 版 本 注 释 >> +namespace SlnMesnac.Business +{ + public class FixedPointBusiness : BaseBusiness + { + + + private readonly Irecord_busbar_tempServices _record_busbar_TempServices; + + public FixedPointBusiness(SerilogHelper log, PlcAbsractFactory plc, Ibase_cabinet_infoServices base_Cabinet_InfoServices, Ibase_busbar_infoServices base_Busbar_InfoServices, Irecord_busbar_tempServices record_busbar_TempServices) : base(log, plc, base_Cabinet_InfoServices, base_Busbar_InfoServices) + { + _record_busbar_TempServices = record_busbar_TempServices; + } + + + public void StartFixedPoint(base_busbar_info busbarInfo) + { + try + { + Task.Run(() => + { + Task.Delay(1000).Wait(); + + base.InitEquip(2); //判断PLC状态,下发工作模式 + + if (!_plc.writeInt32ByAddress("VD1516", 1)) //下发轨道电机启动信号 + { + throw new ArgumentException($"定点巡检模式启动信号写入PLC失败;VD1516写1"); + } + + _log.Info($"定点巡检模式启动信号写入PLC成功;VD1516写1"); + + SendTrackMotorAddress(busbarInfo); + }); + } + catch (Exception ex) + { + throw new InvalidOperationException($"自动巡检逻辑处理异常:{ex.Message}"); + } + } + + public void EndFixedPoint(base_busbar_info busbarInfo) + { + if (busbarInfo.isRotate == 1) + { + GimbaRotationControlEvent?.Invoke("20", "4", "10"); + } + + if (!_plc.writeInt32ByAddress("VD1512", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 + { + throw new ArgumentException($"定点巡检模式下发检测完成信号写入失败;VD1512写1"); + } + _log.Info($"定点巡检模式下发检测完成信号写入PLC成功;VD1512写1"); + _log.Info($"定点巡检结束"); + + } + + + /// + /// 下发轨道电机位置编号 + /// + /// + /// + private void SendTrackMotorAddress(base_busbar_info busbarInfo) + { + if (!_plc.writeInt32ByAddress("VD1520", (int)busbarInfo.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 + { + throw new ArgumentException($"定点巡检模式下发轨道电机前往指定位置编号写入失败;VD1520写{(int)busbarInfo.cabinetCode}"); + } + _log.Info($"定点巡检模式下发轨道电机前往指定位置成功;VD1520写{(int)busbarInfo.cabinetCode}"); + + this.AwaitArriveSignal("VD1528"); //等待轨道相机到位信号 + + this.SendLiftMotorDict(busbarInfo); + + } + + /// + /// 等待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}"); + } + } + + public delegate void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos); + public event GimbaRotationControl GimbaRotationControlEvent; + + + private void SendLiftMotorDict(base_busbar_info busbar) + { + + 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); + } + } + + } +} diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs index 32e220b..299f1b4 100644 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ b/SlnMesnac.Business/base/BaseBusiness.cs @@ -63,20 +63,20 @@ namespace SlnMesnac.Business.@base int plcFlag = 0; do { - plcFlag = _plc.readInt32ByAddress("VD1509"); //PLC状态 + plcFlag = _plc.readInt32ByAddress("VD1508"); //PLC状态 if (plcFlag != 1) { - _log.Info($"PLC状态不具备启动条件:VD1509值为{plcFlag}"); + _log.Info($"PLC状态不具备启动条件:VD1508值为{plcFlag}"); Task.Delay(1000).Wait(); continue; } - if (!_plc.writeInt32ByAddress("VD1533", model)) //工作模式:1-自动;2-巡检;3-手动 + if (!_plc.writeInt32ByAddress("VD1536", model)) //工作模式:1-自动;2-巡检;3-手动 { - throw new ArgumentException($"工作模式:自动模式;写入PLC失败;VD1533写{model}"); + throw new ArgumentException($"工作模式:自动模式;写入PLC失败;VD1536写{model}"); } - _log.Info($"工作模式写入PLC成功;VD1533写{model}"); + _log.Info($"工作模式写入PLC成功;VD1536写{model}"); } while (plcFlag != 1); diff --git a/SlnMesnac.WPF/Page/FixedPointWindow.xaml b/SlnMesnac.WPF/Page/FixedPointWindow.xaml new file mode 100644 index 0000000..8ea1207 --- /dev/null +++ b/SlnMesnac.WPF/Page/FixedPointWindow.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +