V1.0.1.8 -- 2025/12/20
* BMS History Function Improved
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO.Ports;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using LFP_Manager.DataStructure;
|
||||
using LFP_Manager.Function;
|
||||
using LFP_Manager.Utils;
|
||||
@@ -460,10 +461,11 @@ namespace LFP_Manager.Threads
|
||||
break;
|
||||
|
||||
case 2: // Firmware update packet
|
||||
if (OnPrint != null)
|
||||
{
|
||||
OnPrint(this, csLog.trx_data_print(_readBuffer, _readPosition, 1));
|
||||
}
|
||||
SafeRaiseOnPrint(csLog.trx_data_print(_readBuffer, _readPosition, 1));
|
||||
//if (OnPrint != null)
|
||||
//{
|
||||
// OnPrint(this, csLog.trx_data_print(_readBuffer, _readPosition, 1));
|
||||
//}
|
||||
_timeoutCount = 0;
|
||||
ProcessFirmwareResponse();
|
||||
break;
|
||||
@@ -702,5 +704,22 @@ namespace LFP_Manager.Threads
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAFE CALLS
|
||||
private void SafeRaiseOnPrint(string msg)
|
||||
{
|
||||
var handler = OnPrint; // 복사
|
||||
if (handler == null) return;
|
||||
|
||||
// 비차단 + 예외격리: 핸들러를 ThreadPool에서 실행
|
||||
Task.Run(() =>
|
||||
{
|
||||
try { handler.Invoke(this, msg); }
|
||||
catch (Exception ex) { /* 내부 로깅 */ }
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,6 @@ namespace LFP_Manager.Threads
|
||||
|
||||
private ushort ExtReqRegAddr = 0x0000;
|
||||
|
||||
private ushort WriteRegAddr = 0x0000; //Byul Init 0x0000
|
||||
private short WriteCoilRegData = 0;
|
||||
private byte[] WriteRegData;
|
||||
private short WriteParamRegData;
|
||||
|
||||
private TUartTxBuff UartTxBuff;
|
||||
|
||||
public event UartDataUpdateRS485 OnUpdate = null;
|
||||
@@ -139,13 +134,13 @@ namespace LFP_Manager.Threads
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 무시하지 말고 로그 출력
|
||||
OnPrint?.Invoke(this, $"DataRecv Error: {ex.Message}");
|
||||
SafeRaiseOnPrint($"DataRecv Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void sErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
|
||||
{
|
||||
OnPrint?.Invoke(this, $"Serial Error: {e.EventType}");
|
||||
SafeRaiseOnPrint($"Serial Error: {e.EventType}");
|
||||
}
|
||||
|
||||
private void sPinChanged(object sender, System.IO.Ports.SerialPinChangedEventArgs e)
|
||||
@@ -186,7 +181,8 @@ namespace LFP_Manager.Threads
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnPrint?.Invoke(this, $"Error Open - {ex.Message}");
|
||||
SafeRaiseOnPrint($"Error Open - {ex.Message}");
|
||||
|
||||
if (sPort != null)
|
||||
{
|
||||
try { sPort.Dispose(); } catch { }
|
||||
@@ -220,7 +216,7 @@ namespace LFP_Manager.Threads
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnPrint?.Invoke(this, $"Port Close Fail: {ex.Message}");
|
||||
SafeRaiseOnPrint($"Port Close Fail: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,8 +241,6 @@ namespace LFP_Manager.Threads
|
||||
|
||||
public void SetWriteReg(ushort WriteAddr, byte[] WriteData, bool ReplyFlag, int type)
|
||||
{
|
||||
WriteRegAddr = WriteAddr;
|
||||
|
||||
var uartTRxData = new TUartTRxData
|
||||
{
|
||||
type = type,
|
||||
@@ -448,7 +442,7 @@ namespace LFP_Manager.Threads
|
||||
{
|
||||
try
|
||||
{
|
||||
OnPrint?.Invoke(this, $"uartCommThread Start");
|
||||
SafeRaiseOnPrint($"uartCommThread Start");
|
||||
|
||||
int RecvTimeout = (Config != null) ? Config.RecvWaitTime : 1500;
|
||||
int getData = 0;
|
||||
@@ -472,11 +466,11 @@ namespace LFP_Manager.Threads
|
||||
try
|
||||
{
|
||||
sPort.Write(txData, 0, txData.Length);
|
||||
OnPrint?.Invoke(this, csLog.trx_data_print(txData, txData.Length, 0));
|
||||
SafeRaiseOnPrint(csLog.trx_data_print(txData, txData.Length, 0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnPrint?.Invoke(this, $"Write error: {ex.Message}");
|
||||
SafeRaiseOnPrint($"Write error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +513,7 @@ namespace LFP_Manager.Threads
|
||||
case 0: // Need more data
|
||||
break;
|
||||
case 1: // Packet OK, no error
|
||||
OnPrint?.Invoke(this, csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
SafeRaiseOnPrint(csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
|
||||
TimeOutCount[ModuleID - 1] = 0;
|
||||
|
||||
@@ -535,7 +529,7 @@ namespace LFP_Manager.Threads
|
||||
Thread.Sleep(5);
|
||||
goto StartSend;
|
||||
case 2: // Fw Update Packet OK
|
||||
OnPrint?.Invoke(this, csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
SafeRaiseOnPrint(csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
|
||||
TimeOutCount[ModuleID - 1] = 0;
|
||||
rFlag = false;
|
||||
@@ -564,7 +558,8 @@ namespace LFP_Manager.Threads
|
||||
|
||||
if (rPosition > 0)
|
||||
{
|
||||
OnPrint?.Invoke(this, csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
SafeRaiseOnPrint(csLog.trx_data_print(ReadBuf, rPosition, 1));
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
else
|
||||
@@ -595,15 +590,31 @@ namespace LFP_Manager.Threads
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnPrint?.Invoke(this, $"Comm thread error: {ex.Message}");
|
||||
SafeRaiseOnPrint($"Comm thread error: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
SerialPortThreadEnd = true;
|
||||
OnPrint?.Invoke(this, $"uartCommThread End");
|
||||
SafeRaiseOnPrint($"uartCommThread End");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAFE CALLS
|
||||
private void SafeRaiseOnPrint(string msg)
|
||||
{
|
||||
var handler = OnPrint; // 복사
|
||||
if (handler == null) return;
|
||||
|
||||
// 비차단 + 예외격리: 핸들러를 ThreadPool에서 실행
|
||||
Task.Run(() =>
|
||||
{
|
||||
try { handler.Invoke(this, msg); }
|
||||
catch (Exception ex) { /* 내부 로깅 */ }
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user