|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using HybirdFrameworkCore.Utils;
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
|
namespace Service.Led;
|
|
|
|
@ -13,18 +14,14 @@ public class LedClient
|
|
|
|
|
"houtui",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x34, 0xBA, 0xF3, 0xCD, 0xCB, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x0C,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x36,0xCE,0xDE,0xB3,0xB5,0x00,0x00,0x0D,0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"qianjin",
|
|
|
|
|
new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x55, 0xAA, 0x00, 0x00, 0x01, 0x01, 0x00, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
|
|
|
|
|
0x00, 0x0C, 0x00, 0x25, 0x64, 0x69, 0x73, 0x70, 0x30, 0x3A, 0x37, 0xC7, 0xB0, 0xBD, 0xF8, 0x00, 0x00,
|
|
|
|
|
0x0D, 0x0A
|
|
|
|
|
0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x0E,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3B,0x31,0xCD,0xA3,0xD7,0xBC,0xC1,0xCB,0x00,0x00,0x0D,0x0A
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -95,22 +92,36 @@ public class LedClient
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient));
|
|
|
|
|
private static TcpClient? _tcpClient;
|
|
|
|
|
private static Socket? _socket;
|
|
|
|
|
private static string _ip;
|
|
|
|
|
private static int _port;
|
|
|
|
|
|
|
|
|
|
public static bool Init(string ip, int port)
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"begin connect {ip}:{port}");
|
|
|
|
|
_tcpClient = new TcpClient();
|
|
|
|
|
_tcpClient.Connect(ip, port);
|
|
|
|
|
Log.Info($"end connect {ip}:{port} {_tcpClient.Connected}");
|
|
|
|
|
return _tcpClient.Connected;
|
|
|
|
|
_ip = ip;
|
|
|
|
|
_port = port;
|
|
|
|
|
Connect();
|
|
|
|
|
return _socket.Connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Connect()
|
|
|
|
|
{
|
|
|
|
|
Log.Info($"begin connect {_ip}:{_port}");
|
|
|
|
|
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
|
|
|
_socket.NoDelay = true;
|
|
|
|
|
_socket.Connect(_ip, _port);
|
|
|
|
|
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool InnerSend(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
if (_tcpClient?.Connected ?? true)
|
|
|
|
|
Connect();
|
|
|
|
|
if (_socket?.Connected ?? true)
|
|
|
|
|
{
|
|
|
|
|
_tcpClient.GetStream().Write(bytes, 0, bytes.Length);
|
|
|
|
|
_socket?.Send(bytes);
|
|
|
|
|
Log.Info($"send {BitUtls.BytesToHexStr(bytes)}");
|
|
|
|
|
_socket?.Close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|