From 844534ecf6842b54f8676b0c48fb01cc70f899f9 Mon Sep 17 00:00:00 2001 From: wenjy Date: Wed, 27 Nov 2024 18:02:03 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20PLC=E7=B1=BB=E5=9E=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/AutoModeBusiness.cs | 34 +++---- SlnMesnac.Business/base/BaseBusiness.cs | 4 +- SlnMesnac.Plc/Factory/InovanceFactory.cs | 20 ++++ SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs | 20 ++++ SlnMesnac.Plc/Factory/OmronNJFactory.cs | 20 ++++ SlnMesnac.Plc/Factory/SiemensFactory.cs | 96 +++++++++++++++++++- SlnMesnac.Plc/PlcAbsractFactory.cs | 11 +++ SlnMesnac.WPF/appsettings.json | 2 +- 8 files changed, 183 insertions(+), 24 deletions(-) diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index 37dd926..8b815a7 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -59,8 +59,6 @@ namespace SlnMesnac.Business { _record_busbar_TempServices = record_busbar_TempServices; _appConfig = appConfig; - - } public void Start() @@ -114,13 +112,13 @@ namespace SlnMesnac.Business base.InitEquip(1); //判断PLC状态,下发工作模式 - int address = _plc.readInt16ByAddress("VD2005"); //读取轨道电机当前位置,判断原点及起始位置 + int address = _plc.readInt32ByAddress("VD2005"); //读取轨道电机当前位置,判断原点及起始位置 //获取电柜信息 List cabinet_Infos = new List(); base.GetCabinetInfos(address, out cabinet_Infos); - if (!_plc.writeInt16ByAddress("VD1517", 1)) //下发轨道电机启动信号 + if (!_plc.writeInt32ByAddress("VD1517", 1)) //下发轨道电机启动信号 { throw new ArgumentException($"启动信号写入PLC失败;VD1517写1"); } @@ -132,7 +130,7 @@ namespace SlnMesnac.Business this.SendTrackMotorAddress(item); - if (!_plc.writeInt16ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 + if (!_plc.writeInt32ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 { throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败;VD1513写1"); } @@ -156,7 +154,7 @@ namespace SlnMesnac.Business /// private void SendTrackMotorAddress(base_cabinet_info item) { - if (!_plc.writeInt16ByAddress("VD1521", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 + if (!_plc.writeInt32ByAddress("VD1521", item.cabinetCode)) //下发电柜编号,通知轨道电机前往指定电柜位置 { throw new ArgumentException($"下发轨道电机前往指定位置编号写入失败;VD1521写{item.cabinetCode}"); } @@ -166,6 +164,11 @@ namespace SlnMesnac.Business this.SendLiftMotorDict(item.cabinetCode); + if (!_plc.writeInt32ByAddress("VD1521", 0)) + { + throw new ArgumentException($"电柜检测完成轨道电机地址写0失败;VD1521写0"); + } + } /// @@ -180,7 +183,7 @@ namespace SlnMesnac.Business base.GetBusbarInfos(cabinetCode, out busbar_Infos); foreach (var busbar in busbar_Infos) { - if (!_plc.writeDoubleByAddress("VD1525", Convert.ToDouble(busbar.busbarDist))) //下发母排距离,升降电机升降的距离 + if (!_plc.writeFloatByAddress("VD1525", ((float)busbar.busbarDist))) //下发母排距离,升降电机升降的距离 { throw new ArgumentException($"下发母排升降距离写入失败;VD1525写{busbar.cabinetCode}"); } @@ -201,21 +204,12 @@ namespace SlnMesnac.Business this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo,busbar.isPictures); Task.Delay(1000).Wait(); - if (!_plc.writeDoubleByAddress("VD1525", 0)) + if (!_plc.writeFloatByAddress("VD1525", 0)) { throw new ArgumentException($"母排检测完成向PLC升降距离写0失败;VD1525写0"); } _log.Info($"母排检测完成向PLC升降距离写0成功;VD1525写0"); - if (busbar.isEnd == 1) - { - if(!_plc.writeInt16ByAddress("VD1513", 1)) - { - throw new ArgumentException($"最后一层检测完成向PLC写入检测完成信号失败;VD1513写1"); - } - _log.Info($"最后一层检测完成向PLC写入检测完成信号成功;VD1513写1"); - } - if(busbar.isRotate == 1) { GimbaRotationControlEvent?.Invoke("20", "4", "10"); @@ -236,11 +230,11 @@ namespace SlnMesnac.Business bool is_arrive = true; while (is_arrive) { - int is_arrive_flag = _plc.readInt16ByAddress(signal); //读取PLC轨道电机到位信号 + int is_arrive_flag = _plc.readInt32ByAddress(signal); //读取PLC轨道电机到位信号 if (is_arrive_flag == 1) { _log.Info($"PLC已到达指定位置;{signal}值为{is_arrive_flag}"); - if (!_plc.writeInt16ByAddress(signal, 0)) + if (!_plc.writeInt32ByAddress(signal, 0)) { throw new ArgumentException($"PLC到位信号复位失败;{signal}写0"); } @@ -317,7 +311,7 @@ namespace SlnMesnac.Business public int GetTrackMotorAddress() { - int is_arrive_flag = _plc.readInt16ByAddress("VD2005"); + int is_arrive_flag = _plc.readInt32ByAddress("VD2005"); return is_arrive_flag; } diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs index 5b1c2a6..32e220b 100644 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ b/SlnMesnac.Business/base/BaseBusiness.cs @@ -63,7 +63,7 @@ namespace SlnMesnac.Business.@base int plcFlag = 0; do { - plcFlag = _plc.readInt16ByAddress("VD1509"); //PLC状态 + plcFlag = _plc.readInt32ByAddress("VD1509"); //PLC状态 if (plcFlag != 1) { _log.Info($"PLC状态不具备启动条件:VD1509值为{plcFlag}"); @@ -71,7 +71,7 @@ namespace SlnMesnac.Business.@base continue; } - if (!_plc.writeInt16ByAddress("VD1533", model)) //工作模式:1-自动;2-巡检;3-手动 + if (!_plc.writeInt32ByAddress("VD1533", model)) //工作模式:1-自动;2-巡检;3-手动 { throw new ArgumentException($"工作模式:自动模式;写入PLC失败;VD1533写{model}"); } diff --git a/SlnMesnac.Plc/Factory/InovanceFactory.cs b/SlnMesnac.Plc/Factory/InovanceFactory.cs index b0c874b..d20c30a 100644 --- a/SlnMesnac.Plc/Factory/InovanceFactory.cs +++ b/SlnMesnac.Plc/Factory/InovanceFactory.cs @@ -342,5 +342,25 @@ namespace SlnMesnac.Plc.Factory throw new InvalidOperationException($"根据地址:{address};写入double数据异常:{ex.Message}"); } } + + public override bool writeFloatByAddress(string address, float value) + { + throw new NotImplementedException(); + } + + public override int readInt32ByAddress(string address) + { + throw new NotImplementedException(); + } + + public override bool writeInt32ByAddress(string address, int value) + { + throw new NotImplementedException(); + } + + public override float readFloatByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs index 2b58539..6b19ec9 100644 --- a/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs +++ b/SlnMesnac.Plc/Factory/MelsecBinaryFactory.cs @@ -283,5 +283,25 @@ namespace SlnMesnac.Plc.Factory throw new InvalidOperationException($"根据地址:{address};写入double数据异常:{ex.Message}"); } } + + public override bool writeFloatByAddress(string address, float value) + { + throw new NotImplementedException(); + } + + public override int readInt32ByAddress(string address) + { + throw new NotImplementedException(); + } + + public override bool writeInt32ByAddress(string address, int value) + { + throw new NotImplementedException(); + } + + public override float readFloatByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/OmronNJFactory.cs b/SlnMesnac.Plc/Factory/OmronNJFactory.cs index b614e1e..cd98e04 100644 --- a/SlnMesnac.Plc/Factory/OmronNJFactory.cs +++ b/SlnMesnac.Plc/Factory/OmronNJFactory.cs @@ -286,5 +286,25 @@ namespace SlnMesnac.Plc.Factory throw new InvalidOperationException($"根据地址:{address};写入double数据异常:{ex.Message}"); } } + + public override int readInt32ByAddress(string address) + { + throw new NotImplementedException(); + } + + public override bool writeInt32ByAddress(string address, int value) + { + throw new NotImplementedException(); + } + + public override bool writeFloatByAddress(string address, float value) + { + throw new NotImplementedException(); + } + + public override float readFloatByAddress(string address) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/Factory/SiemensFactory.cs b/SlnMesnac.Plc/Factory/SiemensFactory.cs index 7fe9b43..fcf7eef 100644 --- a/SlnMesnac.Plc/Factory/SiemensFactory.cs +++ b/SlnMesnac.Plc/Factory/SiemensFactory.cs @@ -271,7 +271,7 @@ namespace SlnMesnac.Plc.Factory { try { - OperateResult operateResult = s7.Write(address,value); + OperateResult operateResult = s7.Write(address, value); if (!operateResult.IsSuccess) { throw new InvalidOperationException($"根据地址:{address};写入double数据失败:{operateResult.Message}"); @@ -283,5 +283,99 @@ namespace SlnMesnac.Plc.Factory throw new InvalidOperationException($"根据地址:{address};写入double数据异常:{ex.Message}"); } } + + /// + /// 通过PLC地址读取Int32类型数据 + /// + /// + /// + /// + public override int readInt32ByAddress(string address) + { + try + { + OperateResult read = s7.ReadInt32(address); + if (!read.IsSuccess) + { + throw new InvalidOperationException($"根据地址:{address};读取int32数据失败:{read.Content}"); + } + return read.Content; + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据地址:{address};读取int32数据异常:{ex.Message}"); + } + } + + /// + /// 通过PLC地址写入Int32类型数据 + /// + /// + /// + /// + /// + public override bool writeInt32ByAddress(string address, int value) + { + try + { + OperateResult operateResult = s7.Write(address, Convert.ToInt32(value)); + if (!operateResult.IsSuccess) + { + throw new InvalidOperationException($"根据地址:{address};写入int32数据失败:{operateResult.Message}"); + } + return operateResult.IsSuccess; + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据地址:{address};写入int32数据异常:{ex.Message}"); + } + } + + /// + /// 通过PLC地址读取Float类型数据 + /// + /// + /// + /// + public override float readFloatByAddress(string address) + { + try + { + OperateResult read = s7.ReadFloat(address); + if (!read.IsSuccess) + { + throw new InvalidOperationException($"根据地址:{address};读取int32数据失败:{read.Content}"); + } + return read.Content; + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据地址:{address};读取int32数据异常:{ex.Message}"); + } + } + + /// + /// 通过PLC地址写入Float类型数据 + /// + /// + /// + /// + /// + public override bool writeFloatByAddress(string address, float value) + { + try + { + OperateResult operateResult = s7.Write(address, value); + if (!operateResult.IsSuccess) + { + throw new InvalidOperationException($"根据地址:{address};写入float数据失败:{operateResult.Message}"); + } + return operateResult.IsSuccess; + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据地址:{address};写入float数据异常:{ex.Message}"); + } + } } } \ No newline at end of file diff --git a/SlnMesnac.Plc/PlcAbsractFactory.cs b/SlnMesnac.Plc/PlcAbsractFactory.cs index 0f04be2..c126653 100644 --- a/SlnMesnac.Plc/PlcAbsractFactory.cs +++ b/SlnMesnac.Plc/PlcAbsractFactory.cs @@ -20,6 +20,8 @@ * 版本:V1.0.0 *--------------------------------------------------------------------*/ #endregion << 版 本 注 释 >> +using System.ComponentModel; + namespace SlnMesnac.Plc { public abstract class PlcAbsractFactory @@ -105,5 +107,14 @@ namespace SlnMesnac.Plc /// /// public abstract bool writeDoubleByAddress(string address, double value); + + public abstract int readInt32ByAddress(string address); + + public abstract bool writeInt32ByAddress(string address, int value); + + + public abstract float readFloatByAddress(string address); + + public abstract bool writeFloatByAddress(string address, float value); } } \ No newline at end of file diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index c7d35f5..3393026 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -16,7 +16,7 @@ "cameraPort": 8000, "cameraUserName": "admin", "cameraPassword": "haiwei@2024", - "checkCycle": 5, + "checkCycle": 50, "SqlConfig": [ { "configId": "iot",