changed DisconnectedEvent to ConnectionStateChanged event,
fixed exception while unintentional disconnect in SerialProtocol,
implemented connection state indicator in tab header,
resolved warnings
@ -177,9 +190,9 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie
if(this.CommunicationProtocol==null){thrownewNullReferenceException($"'{nameof(SendToCommunicationProtocol)}()' was called but {nameof(CommunicationProtocol)} is null.");}
// inform user and quit if communication protocol is not connected
@ -75,9 +81,9 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
boolsuccess=true;
// guard is not connected => log warning. user of this function shall only use SendBytes if IsConnected is true
if(this.IsConnected==false)
if(this.State!=ProtocolConnectionState.Connected)
{
this.logger.LogWarn($"'{nameof(SendBytes)}()' was reached with {nameof(IsConnected)} being false",nameof(CommunicationProtocol));
this.logger.LogWarn($"'{nameof(SendBytes)}()' was reached with wrong {nameof(ProtocolConnectionState)} of {this.State}",nameof(CommunicationProtocol));
returnfalse;// return and do not send
}
@ -111,9 +117,9 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
publicboolConnect(IProtocolSettingssettings)
{
// check if not already connected
if(this.IsConnected==true)
if(this.State==ProtocolConnectionState.Connected)
{
this.logger.LogWarn($"'{nameof(Connect)}()' was reached even if {nameof(IsConnected)} is already true.",nameof(CommunicationProtocol));
this.logger.LogWarn($"'{nameof(Connect)}()' was reached with wrong {nameof(ProtocolConnectionState)} of {this.State}",nameof(CommunicationProtocol));
returntrue;
}
@ -138,7 +144,7 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
Debug.WriteLine($"{nameof(InternalSendBytes)}() of {nameof(UsbHidProtocol)} took {nextBytes.Count()} bytes and has {bytesToSend.Count} left on queue.");
Debug.WriteLine($"{nameof(InternalSendBytes)}() of {nameof(UsbHidProtocol)} took {nextBytes.Count} bytes and has {bytesToSend.Count} left on queue.");