bugfixes
This commit is contained in:
@@ -60,6 +60,7 @@ namespace SplashEdit.EditorCode
|
||||
private const int FUNC_SEEK = 0x107;
|
||||
|
||||
public bool IsRunning => _listenTask != null && !_listenTask.IsCompleted;
|
||||
public bool HasError { get; private set; }
|
||||
|
||||
public PCdrvSerialHost(string portName, int baudRate, string baseDir, Action<string> log, Action<string> psxLog = null)
|
||||
{
|
||||
@@ -157,6 +158,7 @@ namespace SplashEdit.EditorCode
|
||||
bool lastByteWasEscape = false;
|
||||
var textBuffer = new StringBuilder();
|
||||
int totalBytesReceived = 0;
|
||||
int consecutiveErrors = 0;
|
||||
DateTime lastLogTime = DateTime.Now;
|
||||
|
||||
_log?.Invoke("PCdrv monitor: waiting for data from PS1...");
|
||||
@@ -179,6 +181,7 @@ namespace SplashEdit.EditorCode
|
||||
}
|
||||
|
||||
int b = _port.ReadByte();
|
||||
consecutiveErrors = 0;
|
||||
totalBytesReceived++;
|
||||
|
||||
// Log first bytes received to help diagnose protocol issues
|
||||
@@ -256,8 +259,16 @@ namespace SplashEdit.EditorCode
|
||||
catch (OperationCanceledException) { break; }
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!ct.IsCancellationRequested)
|
||||
_log?.Invoke($"PCdrv monitor error: {ex.Message}");
|
||||
if (ct.IsCancellationRequested) break;
|
||||
consecutiveErrors++;
|
||||
_log?.Invoke($"PCdrv monitor error: {ex.Message}");
|
||||
if (consecutiveErrors >= 3)
|
||||
{
|
||||
_log?.Invoke("PCdrv host: too many errors, connection lost. Stopping.");
|
||||
HasError = true;
|
||||
break;
|
||||
}
|
||||
Thread.Sleep(100); // Back off before retry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user