mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 05:24:12 +08:00
1、设备连接
This commit is contained in:
parent
25fd499773
commit
10cceedd23
@ -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!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新连接客户端,设备信息更新后调用
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <returns></returns>
|
||||
public IDeviceClient? RefreshDeviceClient(DeviceEntity device)
|
||||
{
|
||||
_deviceClients.TryGetValue(device.Id!.Value, out var deviceClient);
|
||||
deviceClient?.DisConnectAsync();
|
||||
return ConnectDevice(device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接云台设备
|
||||
/// </summary>
|
||||
@ -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<VapDeviceService>()!;
|
||||
// var eventService = Locator.Current.GetService<VapEventService>()!;
|
||||
// var constantService = Locator.Current.GetService<VapConstantService>()!;
|
||||
@ -150,4 +169,31 @@ public class DeviceClientService
|
||||
// }
|
||||
// eventService.AddData(eventEntity);
|
||||
}
|
||||
|
||||
#region 业务方法
|
||||
/// <summary>
|
||||
/// 查询设备信息
|
||||
/// </summary>
|
||||
/// <param name="deviceId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public async Task<Dictionary<string, object>?> 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<Dictionary<string, object>>(req);
|
||||
if (resp.IsFailed)
|
||||
{
|
||||
throw new Exception(resp.Message);
|
||||
}
|
||||
return resp.Result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
Loading…
Reference in New Issue
Block a user