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 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,13 +245,23 @@ 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}");
if (_socket.Connected)
{
if (!HeartBegin)
{
HeartBegin = true;
Task.Run(ListenHeart); 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;
} }
} }
@ -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;

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

Loading…
Cancel
Save