introduced InstanceIdentifier and applied it to Tab Title.

master
Jonas Arnold 3 years ago
parent 1fab46d5c5
commit d8670a37db
  1. 8
      MultiTerm.Core/ViewModel/SendReceiveViewModel.cs
  2. 42
      MultiTerm.Core/ViewModel/TerminalViewModel.cs
  3. 1
      MultiTerm.Protocols/CommunicationProtocol.cs
  4. 5
      MultiTerm.Protocols/ICommunicationProtocol.cs
  5. 8
      MultiTerm.Protocols/Serial/SerialProtocol.cs

@ -11,14 +11,6 @@ namespace MultiTerm.Core.ViewModel;
public partial class SendReceiveViewModel : TerminalViewModel
{
public override string Title
{
get
{
return $"{ViewType} {ProtocolType}";
}
}
public override TerminalViewType ViewType => TerminalViewType.SendReceive;
/// <summary>

@ -20,9 +20,42 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie
private readonly IMessenger messenger;
private readonly IContext context;
public abstract string Title { get; }
public abstract TerminalViewType ViewType { get; }
public ProtocolType ProtocolType { get; set; }
public abstract TerminalViewType ViewType { get; }
private ProtocolType protocolType;
public ProtocolType ProtocolType
{
get { return this.protocolType; }
set
{
this.protocolType = value;
this.UpdateTitle();
}
}
#region Title
/// <summary>
/// Terminal title, to allow user to distinguish between different terminals.
/// </summary>
[ObservableProperty]
private string title = string.Empty;
/// <summary>
/// Update the Property <see cref="Title"/>. To be called when it was changed.
/// </summary>
private void UpdateTitle()
{
if(this.CommunicationProtocol == null)
{
this.Title = $"{ProtocolType}";
}
else
{
this.Title = $"{ProtocolType} {this.CommunicationProtocol?.InstanceIdentifier}";
}
}
#endregion
/// <summary>
/// Holds communication data, meaning data that was sent to or received over the communication protocol.
@ -48,7 +81,9 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie
get { return this.communicationProtocol; }
set
{
// store communication protocol
this.communicationProtocol = value;
// register communication protocol in the Communication Data View Model
this.CommunicationData = new CommunicationDataViewModel(this.communicationProtocol, this.context);
@ -126,6 +161,7 @@ public abstract partial class TerminalViewModel : ObservableObject, ITerminalVie
if (CommunicationProtocol == null) { throw new Exception($"To call '{nameof(OnViewModelRequestedConnect)}()', CommunicationProtocol must not be null!"); }
e.Success = this.CommunicationProtocol.Connect(e.Settings);
this.UpdateTitle();
}
private void OnViewModelRequestedDisconnect(object? sender, EventArgs e)

@ -17,6 +17,7 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
public event EventHandler<DisconnectedEventArgs>? DisconnectedEvent;
public abstract ProtocolType ProtocolType { get; }
public abstract string InstanceIdentifier { get; protected set; }
public bool IsConnected { get; private set; } = false;

@ -12,6 +12,11 @@ public interface ICommunicationProtocol
/// </summary>
ProtocolType ProtocolType { get; }
/// <summary>
/// Short identifier string that allows the user to distinguish different instances.
/// </summary>
string InstanceIdentifier { get; }
/// <summary>
/// New data received from connected device.
/// </summary>

@ -10,6 +10,9 @@ namespace MultiTerm.Protocols.Serial;
public class SerialProtocol : CommunicationProtocol
{
public override ProtocolType ProtocolType => ProtocolType.Serial;
public override string InstanceIdentifier { get; protected set; } = string.Empty;
private ISerialProtocolSettings? serialSettings;
private SerialPortStream serialPort = new();
@ -29,6 +32,9 @@ public class SerialProtocol : CommunicationProtocol
// store locally
this.serialSettings = serialProtocolSettings;
// update identifier
this.InstanceIdentifier = this.serialSettings.PortName;
// create new serial port
this.serialPort = new()
{
@ -69,7 +75,7 @@ public class SerialProtocol : CommunicationProtocol
{
while(ct.IsCancellationRequested == false)
{
// reads character based on configured encoding (here Unicode)
// reads character based on configured encoding (here ASCII)
int readCharacter = serialPort.ReadChar();
if (readCharacter != -1) // -1 = timeout
{

Loading…
Cancel
Save