Change console windows title based on connected port and status

This commit is contained in:
Edward Wright 2023-02-16 11:46:21 -05:00
parent 17250a57b5
commit 185e541b12

View File

@ -1,14 +1,14 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Linq;
using System.Management;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace SimplySerial
{
@ -257,6 +257,8 @@ namespace SimplySerial
continue;
}
Console.Title = $"{port.name}: {port.board.make} {port.board.model}";
// if we get this far, clear the screen and send the connection message if not in 'quiet' mode
if (clearScreen)
{
@ -362,6 +364,7 @@ namespace SimplySerial
ExitProgram((e.GetType() + " occurred while attempting to read/write to/from " + port.name + "."), exitCode: -1);
else
{
Console.Title = $"{port.name}: (disconnected)";
Output("\n<<< Communications Interrupted >>>\n");
}
try
@ -375,11 +378,13 @@ namespace SimplySerial
Thread.Sleep(2000); // sort-of arbitrary delay - should be long enough to read the "interrupted" message
if (autoConnect == AutoConnect.ANY)
{
Console.Title = "SimplySerial: Searching...";
port.name = String.Empty;
Output("<<< Attemping to connect to any available COM port. Use CTRL-X to cancel >>>");
}
else if (autoConnect == AutoConnect.ONE)
{
Console.Title = $"{port.name}: Searching...";
Output("<<< Attempting to re-connect to " + port.name + ". Use CTRL-X to cancel >>>");
}
break;
@ -622,6 +627,7 @@ namespace SimplySerial
if (autoConnect == AutoConnect.ANY)
{
Console.Title = "SimplySerial: Searching...";
Output("<<< Attemping to connect to any available COM port. Use CTRL-X to cancel >>>");
}
else if (autoConnect == AutoConnect.ONE)
@ -631,10 +637,16 @@ namespace SimplySerial
Console.Clear();
}
if (port.name == String.Empty)
{
Console.Title = "SimplySerial: Searching...";
Output("<<< Attempting to connect to first available COM port. Use CTRL-X to cancel >>>");
}
else
{
Console.Title = $"{port.name}: Searching...";
Output("<<< Attempting to connect to " + port.name + ". Use CTRL-X to cancel >>>");
}
}
// if we made it this far, everything has been processed and we're ready to proceed!
}