From 643a5ed023cf7bcd26048e2c56599b2fdbab8b73 Mon Sep 17 00:00:00 2001 From: wenjy Date: Thu, 28 Nov 2024 17:21:35 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E8=87=AA=E5=8A=A8=E5=B7=A1?= =?UTF-8?q?=E6=A3=80=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/AutoModeBusiness.cs | 163 ++++++++++++------ SlnMesnac.WPF/MainWindow.xaml | 2 +- SlnMesnac.WPF/Page/IndexControl.xaml | 6 +- SlnMesnac.WPF/Page/IndexControl.xaml.cs | 10 +- .../ViewModel/IndexControlViewModel.cs | 19 ++ SlnMesnac.WPF/appsettings.json | 2 +- 6 files changed, 139 insertions(+), 63 deletions(-) diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index 8b815a7..defc01f 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -61,17 +61,43 @@ namespace SlnMesnac.Business _appConfig = appConfig; } + private bool isFlag = false; + public void Start() { try { - timer = new System.Timers.Timer(1000 * 60 * _appConfig.checkCycle); - timer.Elapsed += new System.Timers.ElapsedEventHandler(AutoModelEvent); - timer.AutoReset = true; - timer.Enabled = false; - timer.Start(); - _log.Info($"自动模式初始化成功"); - this.AutoModelEvent(null, null); + //timer = new System.Timers.Timer(1000 * 60 * _appConfig.checkCycle); + //timer.Elapsed += new System.Timers.ElapsedEventHandler(AutoModelEvent); + //timer.AutoReset = true; + //timer.Enabled = false; + //timer.Start(); + //_log.Info($"自动模式初始化成功"); + //this.AutoModelEvent(null, null); + + if (isFlag) + { + _log.Info($"自动模式运行中,请勿重复开启"); + return; + } + + Task.Run(() => + { + lock (string.Empty) + { + isFlag = true; + while (isFlag) + { + _log.Info($"自动模式初始化成功"); + this.AutoModelEvent(null, null); + + Task.Delay(1000 * 60 * _appConfig.checkCycle).Wait(); + } + } + + }); + + } catch (Exception ex) { @@ -83,13 +109,16 @@ namespace SlnMesnac.Business { try { - if (timer.Enabled) - { - timer.Stop(); - timer.Close(); - timer.Dispose(); - _log.Info($"自动模式关闭成功"); - } + //if (timer.Enabled) + //{ + // timer.Stop(); + // timer.Close(); + // timer.Dispose(); + // _log.Info($"自动模式关闭成功"); + //} + + isFlag = false; + _log.Info($"自动模式关闭成功"); } catch (Exception ex) { @@ -102,49 +131,43 @@ namespace SlnMesnac.Business /// private void AutoModelEvent(object source, System.Timers.ElapsedEventArgs e) { - lock(string.Empty) + try { - try - { - Task.Run(() => - { - Task.Delay(1000).Wait(); - - base.InitEquip(1); //判断PLC状态,下发工作模式 + Task.Delay(1000).Wait(); - int address = _plc.readInt32ByAddress("VD2005"); //读取轨道电机当前位置,判断原点及起始位置 + base.InitEquip(1); //判断PLC状态,下发工作模式 - //获取电柜信息 - List cabinet_Infos = new List(); - base.GetCabinetInfos(address, out cabinet_Infos); + int address = _plc.readInt32ByAddress("VD1100"); //读取轨道电机当前位置,判断原点及起始位置 - if (!_plc.writeInt32ByAddress("VD1517", 1)) //下发轨道电机启动信号 - { - throw new ArgumentException($"启动信号写入PLC失败;VD1517写1"); - } + //获取电柜信息 + List cabinet_Infos = new List(); + base.GetCabinetInfos(address, out cabinet_Infos); - _log.Info($"启动信号写入PLC成功;VD1517写1"); + if (!_plc.writeInt32ByAddress("VD1517", 1)) //下发轨道电机启动信号 + { + throw new ArgumentException($"启动信号写入PLC失败;VD1517写1"); + } - foreach (var item in cabinet_Infos) - { + _log.Info($"启动信号写入PLC成功;VD1517写1"); - this.SendTrackMotorAddress(item); + foreach (var item in cabinet_Infos) + { - if (!_plc.writeInt32ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 - { - throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败;VD1513写1"); - } - Task.Delay(1000).Wait(); - } + this.SendTrackMotorAddress(item); - _log.Info($"巡检结束"); - }); - }catch (Exception ex) - { - throw new InvalidOperationException($"自动巡检逻辑处理异常:{ex.Message}"); + if (!_plc.writeInt32ByAddress("VD1513", 1)) //母排检测完成下发检测完成信号,升降电机可以回到原位等待 + { + throw new ArgumentException($"下发母排检测完成下发检测完成信号写入失败;VD1513写1"); + } + Task.Delay(1000).Wait(); } - } + _log.Info($"巡检结束"); + } + catch (Exception ex) + { + throw new InvalidOperationException($"自动巡检逻辑处理异常:{ex.Message}"); + } } /// @@ -164,10 +187,10 @@ namespace SlnMesnac.Business this.SendLiftMotorDict(item.cabinetCode); - if (!_plc.writeInt32ByAddress("VD1521", 0)) - { - throw new ArgumentException($"电柜检测完成轨道电机地址写0失败;VD1521写0"); - } + //if (!_plc.writeInt32ByAddress("VD1521", 0)) + //{ + // throw new ArgumentException($"电柜检测完成轨道电机地址写0失败;VD1521写0"); + //} } @@ -204,11 +227,11 @@ namespace SlnMesnac.Business this.SaveBusbarTemp(busbar.busbarCode, busbar.cabinetCode, _realTemperatureInfo,busbar.isPictures); Task.Delay(1000).Wait(); - if (!_plc.writeFloatByAddress("VD1525", 0)) - { - throw new ArgumentException($"母排检测完成向PLC升降距离写0失败;VD1525写0"); - } - _log.Info($"母排检测完成向PLC升降距离写0成功;VD1525写0"); + //if (!_plc.writeFloatByAddress("VD1525", 0)) + //{ + // throw new ArgumentException($"母排检测完成向PLC升降距离写0失败;VD1525写0"); + //} + //_log.Info($"母排检测完成向PLC升降距离写0成功;VD1525写0"); if(busbar.isRotate == 1) { @@ -311,10 +334,38 @@ namespace SlnMesnac.Business public int GetTrackMotorAddress() { - int is_arrive_flag = _plc.readInt32ByAddress("VD2005"); + int is_arrive_flag = _plc.readInt32ByAddress("VD1100"); return is_arrive_flag; } + public double GetDeviceSpeed() + { + double speed = _plc.readFloatByAddress("VD2022"); + + return speed; + } + + public string GetDeviceStatus() + { + int deviceStatus = _plc.readInt32ByAddress("VD1509"); + + string deviceStatusFlag = string.Empty; + + if (deviceStatus == 1) + { + deviceStatusFlag = "自动"; + } + else if (deviceStatus == 2) + { + deviceStatusFlag = "本地"; + } + else if (deviceStatus == 3) + { + deviceStatusFlag = "报警"; + } + + return deviceStatusFlag; + } } } diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 89ebda8..d6454cb 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -20,7 +20,7 @@ - + diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml b/SlnMesnac.WPF/Page/IndexControl.xaml index 74b08b3..b20c8f6 100644 --- a/SlnMesnac.WPF/Page/IndexControl.xaml +++ b/SlnMesnac.WPF/Page/IndexControl.xaml @@ -330,7 +330,7 @@ Canvas.Left="245" Canvas.Top="155" Stroke="Transparent" StrokeThickness="1"> - + @@ -339,8 +339,8 @@ Canvas.Left="245" Canvas.Top="155" Stroke="Transparent" StrokeThickness="1"> - - + + diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml.cs b/SlnMesnac.WPF/Page/IndexControl.xaml.cs index f0b67de..67b882e 100644 --- a/SlnMesnac.WPF/Page/IndexControl.xaml.cs +++ b/SlnMesnac.WPF/Page/IndexControl.xaml.cs @@ -241,6 +241,12 @@ namespace SlnMesnac.WPF.Page for (int i = 0; i < 19; i++) { var stationNumber = GetStationNumber(i, true); + + if(stationNumber == 0) + { + continue; + } + Rectangle station = new Rectangle { Width = 35, @@ -343,7 +349,7 @@ namespace SlnMesnac.WPF.Page { List list = new List() { - 26,27,28,29,30,31,32,33,34,1,2,3,4,5,6,7,8,9,10 + 25,26,27,28,29,30,31,32,33,0,1,2,3,4,5,6,7,8,9 }; number = list[i]; @@ -352,7 +358,7 @@ namespace SlnMesnac.WPF.Page { List list = new List() { - 25,24,23,22,21,20,19,18,17,16,15,14,13,12,11 + 24,23,22,21,20,19,18,17,16,15,14,13,12,11,10 }; number = list[i]; diff --git a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs index 33e65e7..77eeed3 100644 --- a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs @@ -96,6 +96,20 @@ namespace SlnMesnac.WPF.ViewModel set => SetProperty(ref _realPlcAddress, value); } + private double _realDeviceSpeed = 0.0; + public double RealDeviceSpeed + { + get => _realDeviceSpeed; + set => SetProperty(ref _realDeviceSpeed, value); + } + + private string _realDeviceStatus = "未连接"; + public string RealDeviceStatus + { + get => _realDeviceStatus; + set => SetProperty(ref _realDeviceStatus, value); + } + public RealTemperatureInfo _realTemperature; public RealTemperatureInfo RealTemperature { @@ -665,6 +679,11 @@ namespace SlnMesnac.WPF.ViewModel RealPlcAddress = trackMotorAddress; RefreshHighlightStationEvent?.Invoke(trackMotorAddress); } + + double speed = autoModeBusiness.GetDeviceSpeed(); + RealDeviceSpeed = Math.Round(speed,2); + string deviceStatus = autoModeBusiness.GetDeviceStatus(); + RealDeviceStatus = deviceStatus; Task.Delay(1000).Wait(); } }); diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 3393026..c7d35f5 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -16,7 +16,7 @@ "cameraPort": 8000, "cameraUserName": "admin", "cameraPassword": "haiwei@2024", - "checkCycle": 50, + "checkCycle": 5, "SqlConfig": [ { "configId": "iot",