From 408beda7db348408537cbf8de19f943de2a68e22 Mon Sep 17 00:00:00 2001 From: wenjy Date: Thu, 12 Dec 2024 10:01:22 +0800 Subject: [PATCH] change - Init --- SlnMesnac.Business/AutoModeBusiness.cs | 12 ++++ SlnMesnac.Business/CabinetInfoBusiness.cs | 14 ++++ SlnMesnac.Business/FixedPointBusiness.cs | 12 ++++ SlnMesnac.Business/InspModeBusiness.cs | 65 +++++++++++++++++-- SlnMesnac.WPF/Page/IndexControl.xaml.cs | 3 +- .../ViewModel/IndexControlViewModel.cs | 40 +++++++++++- 6 files changed, 138 insertions(+), 8 deletions(-) diff --git a/SlnMesnac.Business/AutoModeBusiness.cs b/SlnMesnac.Business/AutoModeBusiness.cs index e9c6574..eddf290 100644 --- a/SlnMesnac.Business/AutoModeBusiness.cs +++ b/SlnMesnac.Business/AutoModeBusiness.cs @@ -286,6 +286,18 @@ namespace SlnMesnac.Business continue; } + int rewrite = _plc.readInt32ByAddress("VD1554"); + if (rewrite == 1) + { + _plc.writeInt32ByAddress("VD1554", 0); + if (!_plc.writeInt32ByAddress("VD1536", 1)) //工作模式:1-自动;2-巡检;3-手动 + { + throw new ArgumentException($"VD1554为1重新写入工作模式:自动模式;写入PLC失败;VD1536写1"); + } + + _log.Info($"VD1554为1重新写入工作模式:自动模式;写入PLC成功;VD1536写1"); + } + _log.Info($"等待PLC前往指定位置;{signal}值为{is_arrive_flag}"); Task.Delay(1000).Wait(); diff --git a/SlnMesnac.Business/CabinetInfoBusiness.cs b/SlnMesnac.Business/CabinetInfoBusiness.cs index 8765cc3..dede45b 100644 --- a/SlnMesnac.Business/CabinetInfoBusiness.cs +++ b/SlnMesnac.Business/CabinetInfoBusiness.cs @@ -7,6 +7,7 @@ using SlnMesnac.Serilog; using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Text; @@ -64,5 +65,18 @@ namespace SlnMesnac.Business infos = _cabinet_infoServices.Query(exp); } + + public void QueryCabinetName(int cabinetCode,out string cabinetName) + { + var info = _cabinet_infoServices.Query(x=>x.cabinetCode == cabinetCode).FirstOrDefault(); + if(info != null) + { + cabinetName = info.cabinetAlias; + } + else + { + cabinetName = $"{cabinetCode}#"; + } + } } } diff --git a/SlnMesnac.Business/FixedPointBusiness.cs b/SlnMesnac.Business/FixedPointBusiness.cs index 991d2a9..8d72b6f 100644 --- a/SlnMesnac.Business/FixedPointBusiness.cs +++ b/SlnMesnac.Business/FixedPointBusiness.cs @@ -140,6 +140,18 @@ namespace SlnMesnac.Business break; } + int rewrite = _plc.readInt32ByAddress("VD1554"); + if (rewrite == 1) + { + _plc.writeInt32ByAddress("VD1554", 0); + if (!_plc.writeInt32ByAddress("VD1536", 3)) //工作模式:1-自动;2-巡检;3-手动 + { + throw new ArgumentException($"VD1554为1重新写入工作模式:自动模式;写入PLC失败;VD1536写3"); + } + + _log.Info($"VD1554为1重新写入工作模式:自动模式;写入PLC成功;VD1536写3"); + } + int is_arrive_flag = _plc.readInt32ByAddress(signal); //读取PLC轨道电机到位信号 if (is_arrive_flag == 1) { diff --git a/SlnMesnac.Business/InspModeBusiness.cs b/SlnMesnac.Business/InspModeBusiness.cs index 346f062..8fe4089 100644 --- a/SlnMesnac.Business/InspModeBusiness.cs +++ b/SlnMesnac.Business/InspModeBusiness.cs @@ -1,4 +1,5 @@ using SlnMesnac.Business.@base; +using SlnMesnac.Config; using SlnMesnac.Model.dto; using SlnMesnac.Plc; using SlnMesnac.Repository; @@ -6,6 +7,7 @@ using SlnMesnac.Repository.service; using SlnMesnac.Serilog; using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -47,27 +49,66 @@ namespace SlnMesnac.Business public delegate void GimbaRotationControl(string wPanPos, string wTiltPos, string wZoomPos); public event GimbaRotationControl GimbaRotationControlEvent; + private readonly AppConfig _appConfig; + public InspModeBusiness( Irecord_inspection_cabinetServices service, - Irecord_busbar_tempServices irecord_Busbar_TempServices,IServiceProvider serviceProvider) : base(serviceProvider) + Irecord_busbar_tempServices irecord_Busbar_TempServices,IServiceProvider serviceProvider,AppConfig appConfig) : base(serviceProvider) { _record_busbar_TempServices = irecord_Busbar_TempServices; _service = service; + _appConfig = appConfig; } public void Start(string taskCode,string filePath) { - if (isFlag) + //if (isFlag) + //{ + // _log.Info($"自动模式运行中,请勿重复开启"); + // return; + //} + + //InspModeEvent(); + + try { - _log.Info($"自动模式运行中,请勿重复开启"); - return; - } - InspModeEvent(); + if (isFlag) + { + _log.Info($"巡检模式运行中,请勿重复开启"); + return; + } + + Task.Run(() => + { + lock (string.Empty) + { + isFlag = true; + while (isFlag) + { + _log.Info($"巡检模式初始化成功"); + this.InspModeEvent(); + + if (isFlag) + { + Task.Delay(1000 * 60 * _appConfig.checkCycle).Wait(); + } + } + } + + }); + + + } + catch (Exception ex) + { + _log.Info($"巡检模式初始化异常:{ex.Message}"); + } } public void Stop() { isFlag = false; + _log.Info($"巡检模式关闭成功"); } private void InspModeEvent() @@ -209,6 +250,18 @@ namespace SlnMesnac.Business break; } + int rewrite = _plc.readInt32ByAddress("VD1554"); + if (rewrite == 1) + { + _plc.writeInt32ByAddress("VD1554", 0); + if (!_plc.writeInt32ByAddress("VD1536", 2)) //工作模式:1-自动;2-巡检;3-手动 + { + throw new ArgumentException($"VD1554为1重新写入工作模式:自动模式;写入PLC失败;VD1536写2"); + } + + _log.Info($"VD1554为1重新写入工作模式:自动模式;写入PLC成功;VD1536写2"); + } + int is_arrive_flag = _plc.readInt32ByAddress(signal); //读取PLC轨道电机到位信号 if (is_arrive_flag == 1) { diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml.cs b/SlnMesnac.WPF/Page/IndexControl.xaml.cs index 0f65452..1b7732f 100644 --- a/SlnMesnac.WPF/Page/IndexControl.xaml.cs +++ b/SlnMesnac.WPF/Page/IndexControl.xaml.cs @@ -357,6 +357,7 @@ namespace SlnMesnac.WPF.Page for (int i = 0; i < 15; i++) { var stationNumber = GetStationNumber(i, false); + indexControlViewModel.QueryCabinetName(stationNumber, out string cabinetName); Rectangle station = new Rectangle { Width = 35, @@ -369,7 +370,7 @@ namespace SlnMesnac.WPF.Page Name = $"station{stationNumber}", ToolTip = new ToolTip { - Content = new TextBlock { Text = stationNumber.ToString().Replace("station",string.Empty) } + Content = new TextBlock { Text = cabinetName } } }; diff --git a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs index 20a0279..16dda30 100644 --- a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs @@ -52,6 +52,8 @@ namespace SlnMesnac.WPF.ViewModel private WebSocketBusiness webSocketBusiness; + private CabinetInfoBusiness cabinetInfoBusiness; + private AppConfig _appConfig; private CHCNetSDK.RemoteConfigCallback _callback; @@ -80,6 +82,7 @@ namespace SlnMesnac.WPF.ViewModel inspModeBusiness = App.ServiceProvider.GetService(); fixedPointBusiness = App.ServiceProvider.GetService(); webSocketBusiness = App.ServiceProvider.GetService(); + cabinetInfoBusiness = App.ServiceProvider.GetService(); autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture; autoModeBusiness.GimbaRotationControlEvent += GimbaRotationControl; @@ -594,13 +597,43 @@ namespace SlnMesnac.WPF.ViewModel } else { + Marshal.FreeHGlobal(ptrPtzCfg); _log.Info("云台旋转控制成功!"); break; } - //Marshal.FreeHGlobal(ptrPtzCfg); + } + + //bool isFlag = true; + //while (isFlag) + //{ + // UInt32 dwReturn = 0; + // Int32 nSize = Marshal.SizeOf(m_struPtzCfg); + // IntPtr ptrPtzCfg = Marshal.AllocHGlobal(nSize); + // Marshal.StructureToPtr(m_struPtzCfg, ptrPtzCfg, false); + // //获取参数失败 + // if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_PTZPOS, -1, ptrPtzCfg, (UInt32)nSize, ref dwReturn)) + // { + // return; + // } + // else + // { + // m_struPtzCfg = (CHCNetSDK.NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPtzCfg, typeof(CHCNetSDK.NET_DVR_PTZPOS)); + // //成功获取显示ptz参数 + // ushort wPanPos2 = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wPanPos, 16)); + + // ushort wTiltPos2 = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wTiltPos, 16)); + // ushort wZoomPos2 = Convert.ToUInt16(Convert.ToString(m_struPtzCfg.wZoomPos, 16)); + // if (Convert.ToString(wPanPos2 * 1f) == wPanPos && Convert.ToString(wTiltPos2 * 1f) == wTiltPos && Convert.ToString(wZoomPos2 * 1f) == wZoomPos) + // { + // isFlag = false; + // } + // } + + // Task.Delay(1000).Wait(); + //} } catch (Exception ex) { @@ -741,5 +774,10 @@ namespace SlnMesnac.WPF.ViewModel } + public void QueryCabinetName(int cabinetCode, out string cabinetName) + { + cabinetInfoBusiness.QueryCabinetName(cabinetCode, out cabinetName); + } + } }