diff --git a/docs/资料/物联网中心/设备接入/力创/命令文档整洁版.xlsx b/docs/资料/物联网中心/设备接入/力创/命令文档整洁版.xlsx index 4e5fba88..cd4a64d8 100644 Binary files a/docs/资料/物联网中心/设备接入/力创/命令文档整洁版.xlsx and b/docs/资料/物联网中心/设备接入/力创/命令文档整洁版.xlsx differ diff --git a/projects/IoT/IoT.Shared/Views/Home/Node.cshtml b/projects/IoT/IoT.Shared/Views/Home/Node.cshtml index 8c1af0be..a270a2c1 100644 --- a/projects/IoT/IoT.Shared/Views/Home/Node.cshtml +++ b/projects/IoT/IoT.Shared/Views/Home/Node.cshtml @@ -170,7 +170,7 @@ -
+
开关 diff --git a/projects/IoT/IoTServices/LiChuangService/Infrastructure/DeviceService.cs b/projects/IoT/IoTServices/LiChuangService/Infrastructure/DeviceService.cs index 986e7425..87c1f02f 100644 --- a/projects/IoT/IoTServices/LiChuangService/Infrastructure/DeviceService.cs +++ b/projects/IoT/IoTServices/LiChuangService/Infrastructure/DeviceService.cs @@ -1,3 +1,7 @@ +using Infrastructure.Extensions; +using Infrastructure.Models; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; using System.Linq; @@ -6,11 +10,6 @@ using System.Net.Sockets; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using Infrastructure.Extensions; -using Infrastructure.Models; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Polly; namespace LiChuangService { @@ -168,7 +167,14 @@ namespace LiChuangService var buffer = new byte[512]; var length = stream.Read(buffer); var data = buffer.ToList().Take(length).ToArray(); - this.Handle(data); + try + { + this.Handle(data); + } + catch (Exception ex) + { + ex.PrintStack(); + } } } }).Start(); @@ -187,13 +193,26 @@ namespace LiChuangService } private void Handle(byte[] data) + { + var list = new List(); + for (int i = 0; i < data.Length; i++) + { + if ((i + 3) < data.Length && data[i] == 0xfe && data[i + 1] == 0xa5) + { + var length = data[i + 3]; + this.HandleInternal(data.Skip(i).Take(5 + length).ToArray()); + } + } + } + + private void HandleInternal(byte[] data) { Console.WriteLine($"read:{BitConverter.ToString(data).Replace("-", " ")}"); var type = data[2]; var command = data[4]; if (command == 0x0c)//16位地址 { - this._address = data.ToList().Skip(5).Take(8).ToArray(); + this._address = this._address ?? data.ToList().Skip(5).Take(8).ToArray(); this._addressValue = BitConverter.ToString(this._address).Replace("-", ""); this.SearchNodeStatus(); } @@ -368,7 +387,7 @@ namespace LiChuangService private void Write(byte[] command) { - Thread.Sleep(200); + Thread.Sleep(500); Console.WriteLine($"write:{BitConverter.ToString(command).Replace("-", " ")}"); this._tcpClient.GetStream().Write(command); }