|
|
|
@ -135,39 +135,45 @@ public class LedClient
|
|
|
|
|
_socket = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly object Locker = new object();
|
|
|
|
|
|
|
|
|
|
public static bool InnerSend(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
if (_socket?.Connected ?? false)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_socket.Send(bytes);
|
|
|
|
|
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (SocketException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"Failed to send data. Reason: {ex.Message}");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
private static bool InnerSend(byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
lock (Locker)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Connect();
|
|
|
|
|
if (_socket?.Connected ?? false)
|
|
|
|
|
{
|
|
|
|
|
_socket.Send(bytes);
|
|
|
|
|
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect");
|
|
|
|
|
return true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_socket.Send(bytes);
|
|
|
|
|
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (SocketException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"Failed to send data. Reason: {ex.Message}");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"Failed to reconnect and send data.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connect();
|
|
|
|
|
if (_socket?.Connected ?? false)
|
|
|
|
|
{
|
|
|
|
|
_socket.Send(bytes);
|
|
|
|
|
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"Failed to reconnect and send data.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|