From c283573b53247033cf83b8fcddd8a022ea6454ab Mon Sep 17 00:00:00 2001 From: IPC-610 <IPC-610@DESKTOP-6LEOOS3> Date: 星期四, 26 九月 2024 08:20:38 +0800 Subject: [PATCH] 修改测试问题 --- Admin.NET/WCS.Application/Hub/PlcHub.cs | 113 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 99 insertions(+), 14 deletions(-) diff --git a/Admin.NET/WCS.Application/Hub/PlcHub.cs b/Admin.NET/WCS.Application/Hub/PlcHub.cs index 31d652c..1075892 100644 --- a/Admin.NET/WCS.Application/Hub/PlcHub.cs +++ b/Admin.NET/WCS.Application/Hub/PlcHub.cs @@ -4,26 +4,27 @@ namespace WCS.Application; /// <summary> -/// PLC闆嗙嚎鍣� +/// 浠诲姟鏃ュ織闆嗙嚎鍣� /// </summary> [MapHub("/hubs/Plc")] public class PlcHub : Hub<IPlcHub> { private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext; - - public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext) + private readonly SysConfigService _sysConfigService; + public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext, SysConfigService sysConfigService) { _plcHubContext = plcHubContext; + _sysConfigService = sysConfigService; } /// <summary> /// 涓嬪彂PLC杩炴帴鐘舵�� /// </summary> /// <param name="context"></param> /// <returns></returns> - //public async Task PublicPlcConn(WcsPlc context) - //{ - // await _plcHubContext.Clients.All.PublicPlcConn(context); - //} + public async Task PublicPlcConn(WcsPlc context) + { + await _plcHubContext.Clients.All.PublicPlcConn(context); + } /// <summary> /// 涓嬪彂宸ヤ綅鐘舵�� @@ -36,12 +37,96 @@ //} /// <summary> - /// 涓嬪彂鎶ヨ淇℃伅 + /// 涓嬪彂鏈嶅姟鐘舵�� /// </summary> - /// <param name="context"></param> - /// <returns></returns> - //public async Task PublicAlarm(WcsAlarmInfoOutput context) - //{ - // await _plcHubContext.Clients.All.PublicAlarm(context); - //} + public async Task UpdateService(PLCServiceModel context) + { + //杩愯鐘舵�� + if (context.BoRunningState.HasValue) + { + PLCTaskAction.boRunningState = context.BoRunningState.Value; + if (context.BoRunningState.Value) + PLCTaskAction.Init(); + else + PLCTaskAction.Stop(); + await _sysConfigService.UpdateConfigValue("sys_RunningState", context.BoRunningState.Value); + } + //鑴辨満妯″紡 + if (context.BoOffline.HasValue) + { + PLCTaskAction.boOffline = context.BoOffline.Value; + await _sysConfigService.UpdateConfigValue("sys_Offline", context.BoOffline.Value); + } + //鑷埛鏂� + if (context.BoRefresh.HasValue) + { + PLCTaskAction.boRefresh = context.BoRefresh.Value; + await _sysConfigService.UpdateConfigValue("sys_Refresh", context.BoRefresh.Value); + } + //婕旂ず妯″紡 + if (context.BoDemo.HasValue) + { + PLCTaskAction.boDemo = context.BoDemo.Value; + + //PLC杩炴帴 + var plcStackeConn = PLCTaskAction.listPlcConn.First(m => m.PlcIP == "10.18.51.120"); + if (plcStackeConn.Connected) + { + //鍐欏叆娴佺▼瀛� + var ret = plcStackeConn.SetPlcDBValue(PLCDataTypeEnum.Bit, "DB119", "0", PLCTaskAction.boDemo == true ? "1" : "0"); + if (ret.IsSucceed) + { + await _sysConfigService.UpdateConfigValue("sys_demo", context.BoDemo.Value); + } + else + { + PLCTaskAction.boDemo = !PLCTaskAction.boDemo; + } + } + else + { + PLCTaskAction.boDemo = !PLCTaskAction.boDemo; + } + } + //婊氱瓛鍙嶈浆 + if (context.BoDrumReversal.HasValue) + { + PLCTaskAction.boDrumReversal = context.BoDrumReversal.Value; + + //PLC杩炴帴 + var plcStackeConn = PLCTaskAction.listPlcConn.First(m => m.PlcIP == "10.18.51.120"); + if (plcStackeConn.Connected) + { + //鍐欏叆娴佺▼瀛� + var ret = plcStackeConn.SetPlcDBValue(PLCDataTypeEnum.Bit, "DB119", "0.1", PLCTaskAction.boDemo == true ? "1" : "0"); + if (ret.IsSucceed) + { + await _sysConfigService.UpdateConfigValue("sys_DrumReversal", context.BoDrumReversal.Value); + } + else + { + PLCTaskAction.boDrumReversal = !PLCTaskAction.boDrumReversal; + } + } + else + { + PLCTaskAction.boDrumReversal = !PLCTaskAction.boDrumReversal; + } + } + await _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() { BoRunningState = PLCTaskAction.boRunningState, BoRefresh = PLCTaskAction.boRefresh, BoOffline = PLCTaskAction.boOffline, BoDemo = PLCTaskAction.boDemo, BoDrumReversal = PLCTaskAction.boDrumReversal }); + } } +public class PLCServiceModel +{ + public bool? BoRunningState { get; set; } + + + public bool? BoOffline { get; set; } + + + public bool? BoRefresh { get; set; } + + public bool? BoDemo { get; set; } + + public bool? BoDrumReversal { get; set; } +} \ No newline at end of file -- Gitblit v1.8.0