Admin.NET/WCS.Application/PLC/PLCTaskAction.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoOutput.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Web/src/views/device/alarmManage/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Web/src/views/wcs/wcsAlarmInfo/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Admin.NET/WCS.Application/PLC/PLCTaskAction.cs
@@ -1,4 +1,5 @@ using Admin.NET.Core.Service; using DocumentFormat.OpenXml.Drawing; using Furion.Logging; using Microsoft.AspNetCore.SignalR; @@ -16,9 +17,10 @@ private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>(); private static readonly IHubContext<PlcHub, IPlcHub> _plcHubContext = App.GetService<IHubContext<PlcHub, IPlcHub>>(); private static List<WcsPlc> listPlc; private static List<WcsDevice> listPlcDevice; private static List<WcsPosition> listPlcStation; private static List<WcsPlc> listPlc = new List<WcsPlc>(); private static List<WcsDevice> listPlcDevice = new List<WcsDevice>(); private static List<WcsPosition> listPlcStation = new List<WcsPosition>(); private static List<WcsAlarmInfo> listAlarmInfo = new List<WcsAlarmInfo>(); private static List<PLCUtil> listPlcUtil = new List<PLCUtil>(); private static CancellationTokenSource cts = new CancellationTokenSource();//取消线程标识 @@ -32,10 +34,6 @@ { //订阅事件 DeviceValueChangeEvent += PLCService.OnChangeEvent; listPlc = _db.Queryable<WcsPlc>().ToList(); listPlcDevice = _db.Queryable<WcsDevice>().ToList(); listPlcStation = _db.Queryable<WcsPosition>().ToList(); } /// <summary> /// 初始化PLC连接 @@ -48,6 +46,7 @@ listPlc = _db.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine || s.Type == PLCTypeEnum.BoxConveyorLine).ToList(); listPlcDevice = _db.Queryable<WcsDevice>().ToList(); listPlcStation = _db.Queryable<WcsPosition>().ToList(); listAlarmInfo = _db.Queryable<WcsAlarmInfo>().ToList(); //等待几秒钟,把已有线程取消掉再连接 Thread.Sleep(5000); foreach (var modPlcUtil in listPlcUtil) @@ -65,6 +64,7 @@ boRunningState = true; StartRead(); ConnectionStatus(); StartWatchAlarm(); } /// <summary> /// 开启读取plc线程 @@ -87,7 +87,7 @@ modPlcUtil.Close(); } break; throw new OperationCanceledException(); //throw new OperationCanceledException(); } try { @@ -149,14 +149,19 @@ { try { while (true) { //取消线程 关闭PLC连接 if (cts.Token.IsCancellationRequested) { foreach (var modPlcUtil in listPlcUtil) { if (modPlcUtil != null && modPlcUtil.Connected) modPlcUtil.Close(); } throw new OperationCanceledException(); break; //throw new OperationCanceledException(); } //获取每个PLC连接状态 foreach (var modPlc in listPlc) @@ -177,7 +182,8 @@ } sysCacheService.Set("PLCCONN" + modPlc.Id, modPlc); } Thread.Sleep(3000); Thread.Sleep(1000); } } catch (OperationCanceledException) { @@ -192,6 +198,70 @@ }); } /// <summary> /// 开启报警监控 /// </summary> public static void StartWatchAlarm() { Task.Run(() => { var listPlc = listAlarmInfo.GroupBy(s => new { s.PlcIP, s.PlcPort }).ToList(); List<PLCUtil> listPlcUtil = new List<PLCUtil>(); int i = 0; foreach (var modPlc in listPlc) { listPlcUtil.Add(new PLCUtil(new WcsPlc() { Id = i++, IP = modPlc.Key.PlcIP, Port = modPlc.Key.PlcPort, PLCType = PLCEnum.S7_1500 })); } while (true) { //取消线程 关闭PLC连接 if (cts.Token.IsCancellationRequested) { foreach (var modPlcUtil in listPlcUtil) { if (modPlcUtil != null && modPlcUtil.Connected) modPlcUtil.Close(); } break; //throw new OperationCanceledException(); } foreach (var modUtil in listPlcUtil) { //报警点位 var listAlarm = listAlarmInfo.Where(s => s.PlcIP == modUtil.PlcId.ToString()); foreach (var modAlarm in listAlarm) { (var result, var value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, modAlarm.AlarmCode, ""); if (result.IsSucceed) { //假设不为0就算报警 if (value != 0) { //修改报警状态同时记录报警日志 modAlarm.AlarmTime = DateTime.Now; modAlarm.Status = YesNoEnum.Y; _db.Updateable(modAlarm).ExecuteCommand(); WcsAlarmLog modLog = modAlarm.Adapt<WcsAlarmLog>(); _db.Insertable(modLog).ExecuteCommand(); //下发报警状态 _plcHubContext.Clients.All.PublicAlarm(modAlarm.Adapt<WcsAlarmInfoOutput>()); } //取消报警 else if (modAlarm.Status == YesNoEnum.Y) { modAlarm.AlarmTime = null; modAlarm.Status = YesNoEnum.N; _db.Updateable(modAlarm).ExecuteCommand(); } } } } Thread.Sleep(1000); } }, cts.Token); } /// <summary> /// 停止服务 /// </summary> Admin.NET/WCS.Application/Service/WcsAlarmInfo/Dto/WcsAlarmInfoOutput.cs
@@ -43,7 +43,7 @@ /// <summary> /// 状态 /// </summary> public int? Status { get; set; } public YesNoEnum? Status { get; set; } /// <summary> /// 设备类型 Admin.NET/WCS.Application/Service/WcsAlarmInfo/WcsAlarmInfoService.cs
@@ -46,6 +46,7 @@ public async Task<long> Add(AddWcsAlarmInfoInput input) { var entity = input.Adapt<WcsAlarmInfo>(); entity.Status = YesNoEnum.N; await _wcsAlarmInfoRep.InsertAsync(entity); return entity.Id; } @@ -103,7 +104,7 @@ public async Task<List<WcsAlarmInfoOutput>> List([FromQuery] PageWcsAlarmInfoInput input) { return await _wcsAlarmInfoRep.AsQueryable() //.WhereIF(!input.Status.IsNullOrEmpty(), s => s.Status == input.Status) .WhereIF(!input.Status.IsNullOrEmpty(), s => s.Status == input.Status) .Select<WcsAlarmInfoOutput>().ToListAsync(); } Web/src/views/device/alarmManage/index.vue
@@ -59,19 +59,44 @@ onMounted(async () => { signalR.off('PublicAlarm'); signalR.on('PublicAlarm', (data: any) => { console.log(data) var listAlarm = tableData.value.filter(t => t.id == data.id); if (listAlarm.length == 0) { tableData.value.unshift(data) console.log(data); // 更新 tableData const index = tableData.value.findIndex(t => t.id == data.id); if (index === -1) { // 如果不存在,添加新数据 tableData.value.unshift(data); tableParams.value.total = tableData.value.length; } else { if (data.status == 1) { // 如果状态为 1,更新数据 tableData.value.splice(index, 1, data); } else { // 如果状态不是 1,报警消除 tableData.value.splice(index, 1); } } // 更新输送线数据 updateCellData(cellsDataOne, data); updateCellData(cellsDataTwo, data); updateCellData(cellsDataThree, data); }); }); // 更新输送线数据的通用函数 function updateCellData(cellsData: any[], data: any) { const foundCell = cellsData.find(cell => cell.Code === data.stationNum); if (foundCell) { if (data.status == 1) { foundCell.IsUse = 4; } else { //如果已经存在就更新数据 const index = tableData.value.findIndex(t => t.id == data.id); tableData.value.splice(index, 1, data); foundCell.IsUse = 0; } }); }); } } //堆垛机数据 const cellsDataLine = [ { Id: 1, Code: '001', LineCode: '', EndLocat: '', IsShow: 1, IsUse: 0, BoxHeight: 10 }, @@ -1885,36 +1910,23 @@ tableData.value = res.data.result; tableParams.value.total = tableData.value.length; //处理一楼输送线数据 tableData.value.forEach((item) => { const foundCell = cellsDataOne.find(cell => cell.Code === item.stationNum); if (foundCell) { foundCell.IsUse = 4; } }); //加载输送线数据 cellsData.value =cellsDataOne; //处理二楼输送线数据 tableData.value.forEach((item) => { const foundCell = cellsDataTwo.find(cell => cell.Code === item.stationNum); if (foundCell) { foundCell.IsUse = 4; } }); //处理三楼输送线数据 tableData.value.forEach((item) => { const foundCell = cellsDataThree.find(cell => cell.Code === item.stationNum); if (foundCell) { foundCell.IsUse = 4; } }); // 更新输送线数据 updateCells(cellsDataOne); updateCells(cellsDataTwo); updateCells(cellsDataThree); console.log(tableParams.value.total); loading.value = false; }; // 更新输送线数据的通用函数 function updateCells(cellsData: any[]) { tableData.value.forEach((item) => { updateCellData(cellsData, item); }); } handleQuery(); //复位报警 @@ -2063,7 +2075,8 @@ gap: 0px; /* Gap between cells */ margin-top: -20px;; margin-top: -20px; ; } .grid-item { @@ -2097,13 +2110,16 @@ .active2>div { display: none; } .active3 { background-color: #fff; border:1px solid red; } .active3>div { display: none; } .active4 { background-color: red; } Web/src/views/wcs/wcsAlarmInfo/index.vue
@@ -59,7 +59,7 @@ <el-table-column prop="alarmCode" label="报警编号" show-overflow-tooltip="" /> <el-table-column prop="alarmName" label="报警描述" show-overflow-tooltip="" /> <el-table-column prop="ledIP" label="显示屏ip地址" show-overflow-tooltip="" /> <el-table-column prop="status" label="状态" show-overflow-tooltip=""> <el-table-column prop="status" label="是否报警" show-overflow-tooltip=""> <template #default="scope"> <el-tag :type="dv('YesNoEnum', scope.row.status)?.tagType"> {{ dv('YesNoEnum', scope.row.status)?.name}}</el-tag>