|
|
|
@ -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<byte[]>();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|