From 10cceedd2335d732f4b314c69f046bca968de284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E7=8E=AE?= Date: Fri, 15 Nov 2024 10:56:24 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AE=BE=E5=A4=87=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detect.gui/Services/DeviceClientService.cs | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/detect.gui/Services/DeviceClientService.cs b/detect.gui/Services/DeviceClientService.cs index 28b89bc..cab47b6 100644 --- a/detect.gui/Services/DeviceClientService.cs +++ b/detect.gui/Services/DeviceClientService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using detect.device; using detect.device.Utils; using detect.gui.Models.Entities; @@ -72,6 +73,18 @@ public class DeviceClientService return ConnectDevice(eventService.ListById(deviceId).Result!); } + /// + /// 刷新连接客户端,设备信息更新后调用 + /// + /// + /// + public IDeviceClient? RefreshDeviceClient(DeviceEntity device) + { + _deviceClients.TryGetValue(device.Id!.Value, out var deviceClient); + deviceClient?.DisConnectAsync(); + return ConnectDevice(device); + } + /// /// 连接云台设备 /// @@ -106,7 +119,13 @@ public class DeviceClientService private void DeviceClientOnDeviceEvent(object? sender, DeviceEvent e) { - Log.Information("DeviceEvent-[{Name}]:{@Result}", e.Name, e.Result); + Log.Information("DeviceEvent-[{Name}]-{Address}:{@Result}", e.Name, (sender as DeviceClientSocket)!.Address, e.Result); + if (e.Name == detect.device.DeviceEvent.EventDeviceConnected) + { + var sysInfo = GetDeviceInfo(1).GetAwaiter().GetResult(); + Log.Information("device info: {@Info}", sysInfo); + } + // var deviceService = Locator.Current.GetService()!; // var eventService = Locator.Current.GetService()!; // var constantService = Locator.Current.GetService()!; @@ -150,4 +169,31 @@ public class DeviceClientService // } // eventService.AddData(eventEntity); } + + #region 业务方法 + /// + /// 查询设备信息 + /// + /// + /// + /// + public async Task?> GetDeviceInfo(long deviceId) + { + var deviceClient = GetDeviceClient(deviceId); + if (deviceClient == null) + { + throw new Exception("设备未连接!"); + } + + var req = DeviceClientRequestBuilder.Create().WithType("service").WithComponent("_database") + .WithMethod("system_info"); + var resp = await deviceClient.RequestAction>(req); + if (resp.IsFailed) + { + throw new Exception(resp.Message); + } + return resp.Result; + } + + #endregion } \ No newline at end of file