led连接相关

master
lxw 4 weeks ago
parent 6738f669fa
commit 181e5608fb

@ -181,8 +181,11 @@ public class LedClient
// private static string _ip = "127.0.0.1";
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[]
{
@ -242,20 +245,30 @@ public class LedClient
_socket.NoDelay = true;
_socket.Connect(_ip, _port);
Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");
Task.Run(ListenHeart);
if (_socket.Connected)
{
if (!HeartBegin)
{
HeartBegin = true;
Task.Run(ListenHeart);
}
}
}
catch (SocketException ex)
{
Log.Error($"Failed to connect to {_ip}:{_port}. Reason: {ex.Message}");
_socket?.Close();
_socket = null;
}
}
private static bool InnerSend(byte[] bytes)
{
if (_socket?.Connected ?? false)
if ( _socket?.Connected ?? false )
{
try
{
@ -295,19 +308,8 @@ public class LedClient
int count = 0;
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;

@ -82,7 +82,7 @@ public class UpdateDownBatteryInfoTask : ITask
battery.DownBatterySoc = info.Soc;
battery.DownBatterySoe = info.Soe;
battery.DownNominalEnergy = info.NominalEnergy;
Log.Info($"add battery battery ={JsonConvert.SerializeObject(battery)}");
updateDbBattery.Add(battery);

Loading…
Cancel
Save