Skip to content

Commit

Permalink
show s88 device info
Browse files Browse the repository at this point in the history
disable async open mode which is NOT supported
  • Loading branch information
Christian Benjamin Ries committed Jul 29, 2024
1 parent e487a57 commit 1bf300a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Source/EsuEcosMiddleman/HSI88USB/DeviceInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ public async Task RunAsync()

try
{
_fs = new FileStream(_handle, FileAccess.ReadWrite, buffer.Length, isAsync: true);
_fs = new FileStream(_handle, FileAccess.ReadWrite, buffer.Length, isAsync: false);
}
catch (Exception ex)
{
ex.ShowException();

Failed?.Invoke(this, EventArgs.Empty);
Failed?.Invoke(this, new DeviceInterfaceEventArgs(ex.GetExceptionMessages()));

// highly fatal, no S88-data will be received nor handled
return;
Expand All @@ -211,6 +211,12 @@ public async Task RunAsync()
//var d2 = new DeviceInterfaceData(Encoding.ASCII.GetString(buffer, 0, bytesRead));
//DataReceived?.Invoke(this, d2);

// query device information/version
Send($"v\r");
bytesRead = _fs.Read(buffer, 0, buffer.Length);
var d2 = new DeviceInterfaceData(Encoding.ASCII.GetString(buffer, 0, bytesRead));
DataReceived?.Invoke(this, d2);

var tkn = _cancellationToken.Token;

while (!tkn.IsCancellationRequested)
Expand Down
13 changes: 12 additions & 1 deletion Source/EsuEcosMiddleman/Middleman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,21 @@ private void SendCurrentHsi88States()

private readonly ConcurrentDictionary<int, string> _hsiStates = new ConcurrentDictionary<int, string>();

private bool _versionShown = false;

private void Hsi88DeviceOnDataReceived(object sender, DeviceInterfaceData data)
{
_cfgRuntime.Logger?.Log.Debug($"HSI-88: {data.Data}");

if (!_versionShown && data.Data.StartsWith("V", StringComparison.OrdinalIgnoreCase))
{
_versionShown = true;

_cfgRuntime.Logger?.Log.Info($"HSI-88: {data.Data}");

return;
}

foreach (var it in data.States)
{
_cfgRuntime.Logger?.Log.Debug($"{it.Key} => {it.Value}");
Expand Down Expand Up @@ -294,7 +305,7 @@ private void TcpServerInstanceOnMessageReceived(object sender, MessageEventArgs
}

_cfgRuntime.Logger?.Log.Debug($"Ecos [out]: {eventargs.Message}");

_handler.SendToEcos(eventargs.Message);
}

Expand Down

0 comments on commit 1bf300a

Please sign in to comment.