From eff7a7ff6ee1851094dfe1f94dd40a98535865d8 Mon Sep 17 00:00:00 2001 From: hwh <332078369@qq.com> Date: 星期二, 10 九月 2024 17:00:08 +0800 Subject: [PATCH] 设备通讯 --- Web/src/views/device/deviceMonitor/signalR.ts | 16 ++++++++++++++-- Web/src/views/device/deviceMonitor/index.vue | 17 ++++++++++------- Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs | 20 +++++++++++++++----- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs b/Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs index ff0eeb4..7a8ff9c 100644 --- a/Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs +++ b/Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs @@ -88,7 +88,8 @@ { throw new OperationCanceledException(); } - var modPlc = listPlc.Where(s => s.Id == modDevice.Id).FirstOrDefault(); + var modPlc = listPlc.Where(s => s.Id == modDevice.PlcId).FirstOrDefault(); + modDevice.Type = modPlc.Type; //璇诲彇plc鐨勫�� var modConn = PLCTaskAction.listPlcConn.FirstOrDefault(s => s != null && s.PlcId == modDevice.PlcId); if (modConn == null) @@ -155,6 +156,15 @@ modDevice.PickStorey = Convert.ToInt32(pickStorey); } } + //else + //{ + // //娴嬭瘯 + // modDevice.TaskNo = "TK00001"; + // modDevice.TaskType = TaskTypeEnum.In; + // modDevice.Wcs = new Random().Next(1000).ToString(); + // modDevice.Plc = new Random().Next(1000).ToString(); + // modDevice.Status = true; + //} // 姣旇緝涔嬪墠鐨勭姸鎬� if (initialStates.TryGetValue(modDevice.Id, out var initialState)) { @@ -178,17 +188,17 @@ _plcDeviceHubContext.Clients.All.PublicPlcDevice(modDevice); } } - initialStates[modDevice.Id] = modDevice.Adapt<WcsDeviceOutput>(); - - } Thread.Sleep(2000); + } + catch (OperationCanceledException) + { + break; } catch (Exception) { - throw; } } }, cts.Token); diff --git a/Web/src/views/device/deviceMonitor/index.vue b/Web/src/views/device/deviceMonitor/index.vue index b404ddf..f66cf15 100644 --- a/Web/src/views/device/deviceMonitor/index.vue +++ b/Web/src/views/device/deviceMonitor/index.vue @@ -114,13 +114,13 @@ </template> <script lang="ts" setup> -import { ref, onMounted } from 'vue'; +import { ref, onMounted } from 'vue'; import { listWcsDevice, writeValue } from '/@/api/wcs/wcsDevice'; import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils'; import { listWcsPlc } from '/@/api/wcs/wcsPlc'; import { ElMessageBox, ElMessage } from 'element-plus'; import setting from '/@/views/device/deviceMonitor/component/setting.vue' -import { signalR } from './signalR'; +import { signalR,stopConnection } from './signalR'; //杩炴帴signalR 鐩戝惉鍙樻洿 onMounted(async () => { signalR.off('PublicPlcDevice'); @@ -133,12 +133,15 @@ } } else if (data.type == 1) { - stations.value.forEach(list => { - var index = list.findIndex(s => s.id == data.id); + lineOptions.value.forEach(s => { + var index = stations.value[s.id].findIndex(s => s.id == data.id); if (index !== -1) { - list.splice(index, 1, data); + stations.value[s.id].splice(index, 1, data); } }); + if (stationValue.value.id == data.id) { + stationValue.value = data; + } } }); }); @@ -169,10 +172,10 @@ } // 鏌ヨ鎿嶄綔 const handleQuery = async () => { - var listplc = await listWcsPlc({ type: 1 }); + const listplc = await listWcsPlc({ type: 1 }); lineOptions.value = listplc.data.result; lineValue.value = listplc.data.result[0].id; - var res = await listWcsDevice(); + const res = await listWcsDevice(); listStackingMachineData.value = res.data.result.filter(s => s.type == 0); const listConveyorLineData = res.data.result.filter(s => s.type == 1); listplc.data.result.forEach(s => { diff --git a/Web/src/views/device/deviceMonitor/signalR.ts b/Web/src/views/device/deviceMonitor/signalR.ts index efcbe5b..9876733 100644 --- a/Web/src/views/device/deviceMonitor/signalR.ts +++ b/Web/src/views/device/deviceMonitor/signalR.ts @@ -17,21 +17,33 @@ // 鍚姩杩炴帴 connection.start().then(() => { + debugger; console.log('鍚姩杩炴帴plc'); }); // 鏂紑杩炴帴 connection.onclose(async () => { + debugger; console.log('鏂紑杩炴帴plc'); }); // 閲嶈繛涓� connection.onreconnecting(() => { + debugger; console.log('鏈嶅姟鍣ㄥ凡鏂嚎plc'); }); // 閲嶈繛鎴愬姛 connection.onreconnected(() => { + debugger; console.log('閲嶈繛鎴愬姛plc'); }); - +// 鍏抽棴杩炴帴鐨勬柟娉� +async function stopConnection() { + try { + await connection.stop(); + console.log('杩炴帴宸插叧闂�'); + } catch (error) { + console.error('鍏抽棴杩炴帴鏃跺彂鐢熼敊璇�:', error); + } + } // connection.on('PublicPlcConn', () => {}); -export { connection as signalR }; +export { connection as signalR,stopConnection }; -- Gitblit v1.8.0