|
|
@ -181,8 +181,11 @@ public class LedClient
|
|
|
|
// private static string _ip = "127.0.0.1";
|
|
|
|
// private static string _ip = "127.0.0.1";
|
|
|
|
private static int _port = 10000;
|
|
|
|
private static int _port = 10000;
|
|
|
|
|
|
|
|
|
|
|
|
private static DateTime LastestSendTime;
|
|
|
|
|
|
|
|
private static string LastestKey=InfoEnum.SwapInfo.WelcomeInfo.GetLed();
|
|
|
|
private static string LastestKey=InfoEnum.SwapInfo.IDEI.GetLed();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool HeartBegin = false;
|
|
|
|
|
|
|
|
|
|
|
|
private static byte[] Heart = new byte[]
|
|
|
|
private static byte[] Heart = new byte[]
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -242,20 +245,30 @@ public class LedClient
|
|
|
|
_socket.NoDelay = true;
|
|
|
|
_socket.NoDelay = true;
|
|
|
|
_socket.Connect(_ip, _port);
|
|
|
|
_socket.Connect(_ip, _port);
|
|
|
|
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
|
|
|
|
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
|
|
|
|
Task.Run(ListenHeart);
|
|
|
|
|
|
|
|
|
|
|
|
if (_socket.Connected)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!HeartBegin)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
HeartBegin = true;
|
|
|
|
|
|
|
|
Task.Run(ListenHeart);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (SocketException ex)
|
|
|
|
catch (SocketException ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Error($"Failed to connect to {_ip}:{_port}. Reason: {ex.Message}");
|
|
|
|
Log.Error($"Failed to connect to {_ip}:{_port}. Reason: {ex.Message}");
|
|
|
|
_socket?.Close();
|
|
|
|
_socket?.Close();
|
|
|
|
_socket = null;
|
|
|
|
_socket = null;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool InnerSend(byte[] bytes)
|
|
|
|
private static bool InnerSend(byte[] bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_socket?.Connected ?? false)
|
|
|
|
if ( _socket?.Connected ?? false )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -295,19 +308,8 @@ public class LedClient
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
if (Dictionary.TryGetValue(key, out var bytes))
|
|
|
|
if (Dictionary.TryGetValue(key, out var bytes))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LastestKey = key;
|
|
|
|
|
|
|
|
LastestSendTime=DateTime.Now;
|
|
|
|
|
|
|
|
while (!InnerSend(bytes))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (count > 10)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return InnerSend(bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|