mirror of
https://github.com/fasteddy516/SimplySerial.git
synced 2024-11-24 10:04:35 +00:00
Change console windows title based on connected port and status
This commit is contained in:
parent
17250a57b5
commit
185e541b12
@ -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;
|
||||
@ -410,7 +415,7 @@ namespace SimplySerial
|
||||
foreach (string arg in args)
|
||||
{
|
||||
// split argument into components based on 'key:value' formatting
|
||||
string[] argument = arg.Split(new [] { ':' }, 2);
|
||||
string[] argument = arg.Split(new[] { ':' }, 2);
|
||||
argument[0] = argument[0].ToLower();
|
||||
|
||||
// help
|
||||
@ -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,9 +637,15 @@ 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!
|
||||
@ -644,7 +656,7 @@ namespace SimplySerial
|
||||
/// Writes messages using Console.WriteLine() as long as the 'Quiet' option hasn't been enabled
|
||||
/// </summary>
|
||||
/// <param name="message">Message to output (assuming 'Quiet' is false)</param>
|
||||
static void Output(string message, bool force=false, bool newline=true, bool flush=false)
|
||||
static void Output(string message, bool force = false, bool newline = true, bool flush = false)
|
||||
{
|
||||
if (!SimplySerial.Quiet || force)
|
||||
{
|
||||
@ -665,7 +677,7 @@ namespace SimplySerial
|
||||
foreach (byte c in message)
|
||||
{
|
||||
if ((c > 31 && c < 128) || (c == 8) || (c == 9) || (c == 10) || (c == 13))
|
||||
newMessage += (char) c;
|
||||
newMessage += (char)c;
|
||||
else
|
||||
newMessage += $"[{c:X2}]";
|
||||
}
|
||||
@ -761,7 +773,7 @@ namespace SimplySerial
|
||||
/// <param name="message">Message to display - should indicate the reason why the program is terminating.</param>
|
||||
/// <param name="exitCode">Code to return to parent process. Should be <0 if an error occurred, >=0 if program is terminating normally.</param>
|
||||
/// <param name="silent">Exits without displaying a message or asking for a key press when set to 'true'</param>
|
||||
static void ExitProgram(string message="", int exitCode=0, bool silent=false)
|
||||
static void ExitProgram(string message = "", int exitCode = 0, bool silent = false)
|
||||
{
|
||||
// the serial port should be closed before exiting
|
||||
if (serialPort != null && serialPort.IsOpen)
|
||||
@ -881,7 +893,7 @@ namespace SimplySerial
|
||||
|
||||
if (mBoard == null)
|
||||
{
|
||||
mBoard = new Board(vid:vid, pid:pid);
|
||||
mBoard = new Board(vid: vid, pid: pid);
|
||||
|
||||
Vendor mVendor = null;
|
||||
if (boardData.vendors != null)
|
||||
|
Loading…
Reference in New Issue
Block a user