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