From 1975f9e8547d6a5710408487ee1f557a68e61313 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期二, 15 十月 2024 08:43:31 +0800 Subject: [PATCH] 工作台页面增加出库锁定和入库锁定开关,任务管理页面增加置顶任务功能 --- Admin.NET/WCS.Application/Hub/PlcHub.cs | 186 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 181 insertions(+), 5 deletions(-) diff --git a/Admin.NET/WCS.Application/Hub/PlcHub.cs b/Admin.NET/WCS.Application/Hub/PlcHub.cs index f85da61..a7caaa5 100644 --- a/Admin.NET/WCS.Application/Hub/PlcHub.cs +++ b/Admin.NET/WCS.Application/Hub/PlcHub.cs @@ -1,5 +1,6 @@ 锘縰sing Furion.InstantMessaging; using Microsoft.AspNetCore.SignalR; +using WCS.Application.Entity; namespace WCS.Application; @@ -10,10 +11,13 @@ public class PlcHub : Hub<IPlcHub> { private readonly IHubContext<PlcHub, IPlcHub> _plcHubContext; - - public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext) + private readonly SysConfigService _sysConfigService; + private readonly SqlSugarRepository<WcsCheckTask> _wcsCheckTaskRep; + public PlcHub(IHubContext<PlcHub, IPlcHub> plcHubContext, SysConfigService sysConfigService, SqlSugarRepository<WcsCheckTask> wcsCheckTaskRep) { _plcHubContext = plcHubContext; + _sysConfigService = sysConfigService; + _wcsCheckTaskRep = wcsCheckTaskRep; } /// <summary> /// 涓嬪彂PLC杩炴帴鐘舵�� @@ -48,23 +52,195 @@ 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 _plcHubContext.Clients.All.UpdateService(context); + await _sysConfigService.UpdateConfigValue("sys_Refresh", context.BoRefresh.Value); + } + //婕旂ず妯″紡 + if (context.BoDemo.HasValue) + { + PLCTaskAction.boDemo = context.BoDemo.Value; + + if (PLCTaskAction.boDemo) + { + //鍒ゆ柇鍒嗘嫞鐮佸灈鏈夋病鏈夌粦瀹氫换鍔� + var checkTask = await _wcsCheckTaskRep.Context.Queryable<WcsCheckTask>().Where(w => w.Status == "1" && w.RoboatType == PLCTypeEnum.RobotPalletizer).ToListAsync(); + if (checkTask.Count > 0) + { + PLCTaskAction.boDemo = false; + await _plcHubContext.Clients.All.UpdateService( + new PLCServiceModel() + { + BoRunningState = PLCTaskAction.boRunningState, + BoRefresh = PLCTaskAction.boRefresh, + BoOffline = PLCTaskAction.boOffline, + BoDemo = PLCTaskAction.boDemo, + BoDrumReversal = PLCTaskAction.boDrumReversal, + Error = "鍒嗘嫞鐮佸灈宸茬粦瀹氫换鍔★紝涓嶆敮鎸佸紑鍚紨绀烘ā寮忥紒" + }); + return; + } + } + //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) + { + if (PLCTaskAction.boDemo) + { + // 鍐欏叆plc鎶撶鍝佺 + var rett = plcStackeConn.SetPlcDBValue(PLCDataTypeEnum.Short, "DB111", "0", "1"); + if (rett.IsSucceed) + { + await _sysConfigService.UpdateConfigValue("sys_demo", context.BoDemo.Value); + } + } + else + { + var rett = plcStackeConn.SetPlcDBValue(PLCDataTypeEnum.Short, "DB111", "0", "0"); + if (rett.IsSucceed) + { + await _sysConfigService.UpdateConfigValue("sys_demo", context.BoDemo.Value); + } + } + } + else + { + PLCTaskAction.boDemo = !PLCTaskAction.boDemo; + + await _plcHubContext.Clients.All.UpdateService( + new PLCServiceModel() + { + BoRunningState = PLCTaskAction.boRunningState, + BoRefresh = PLCTaskAction.boRefresh, + BoOffline = PLCTaskAction.boOffline, + BoDemo = PLCTaskAction.boDemo, + BoDrumReversal = PLCTaskAction.boDrumReversal, + BoOutLock=PLCTaskAction.boOutLock, + BoEnterLock=PLCTaskAction.boEnterLock, + Error = "涓嶱CL浜や簰澶辫触锛屾搷浣滃け璐ワ紒" + }); + return; + } + } + else + { + PLCTaskAction.boDemo = !PLCTaskAction.boDemo; + + await _plcHubContext.Clients.All.UpdateService( + new PLCServiceModel() + { + BoRunningState = PLCTaskAction.boRunningState, + BoRefresh = PLCTaskAction.boRefresh, + BoOffline = PLCTaskAction.boOffline, + BoDemo = PLCTaskAction.boDemo, + BoDrumReversal = PLCTaskAction.boDrumReversal, + BoOutLock = PLCTaskAction.boOutLock, + BoEnterLock = PLCTaskAction.boEnterLock, + Error = "PCL鏈繛鎺ワ紝鎿嶄綔澶辫触锛�" + }); + return; + } + } + //婊氱瓛鍙嶈浆 + 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; + + await _plcHubContext.Clients.All.UpdateService( + new PLCServiceModel() + { + BoRunningState = PLCTaskAction.boRunningState, + BoRefresh = PLCTaskAction.boRefresh, + BoOffline = PLCTaskAction.boOffline, + BoDemo = PLCTaskAction.boDemo, + BoDrumReversal = PLCTaskAction.boDrumReversal, + BoOutLock=PLCTaskAction.boOutLock, + BoEnterLock=PLCTaskAction.boEnterLock, + Error = "涓嶱CL浜や簰澶辫触锛屾搷浣滃け璐ワ紒" + }); + return; + } + } + 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, + BoOutLock = PLCTaskAction.boOutLock, + BoEnterLock = PLCTaskAction.boEnterLock, + Error = "PCL鏈繛鎺ワ紝鎿嶄綔澶辫触锛�" + }); + return; + } + } + //鍑哄簱閿佸畾 + if (context.BoOutLock.HasValue) + { + PLCTaskAction.boOutLock = context.BoOutLock.Value; + await _sysConfigService.UpdateConfigValue("sys_BoOutLock", context.BoOutLock.Value); + } + //鍏ュ簱閿佸畾 + if (context.BoEnterLock.HasValue) + { + PLCTaskAction.boEnterLock = context.BoEnterLock.Value; + await _sysConfigService.UpdateConfigValue("sys_BoEnterLock", context.BoEnterLock.Value); + } + await _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() { BoRunningState = PLCTaskAction.boRunningState, BoRefresh = PLCTaskAction.boRefresh, BoOffline = PLCTaskAction.boOffline, BoDemo = PLCTaskAction.boDemo, BoDrumReversal = PLCTaskAction.boDrumReversal, BoOutLock = PLCTaskAction.boOutLock, BoEnterLock = PLCTaskAction.boEnterLock }); } } 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; } + + public bool? BoOutLock { get; set; } + + public bool? BoEnterLock { get; set; } + + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string Error { get; set; } } \ No newline at end of file -- Gitblit v1.8.0