Added command-line argument to set logging buffer size

This commit is contained in:
Edward Wright 2021-05-09 21:11:55 -04:00
parent 43a6d90ead
commit 1a35131c47

View File

@ -13,7 +13,6 @@ namespace SimplySerial
class SimplySerial class SimplySerial
{ {
const string version = "0.5.0-beta"; const string version = "0.5.0-beta";
const int bufferSize = 4096;
static List<ComPort> availablePorts; static List<ComPort> availablePorts;
static SerialPort serialPort; static SerialPort serialPort;
@ -32,6 +31,7 @@ namespace SimplySerial
static FileMode logMode = FileMode.Create; static FileMode logMode = FileMode.Create;
static string logFile = string.Empty; static string logFile = string.Empty;
static string logData = string.Empty; static string logData = string.Empty;
static int bufferSize = 4096;
static void Main(string[] args) static void Main(string[] args)
@ -430,6 +430,23 @@ namespace SimplySerial
ExitProgram(("Invalid log mode setting specified <" + argument[1] + ">"), exitCode: -1); ExitProgram(("Invalid log mode setting specified <" + argument[1] + ">"), exitCode: -1);
} }
// set size of logging buffer
else if (argument[0].StartsWith("logb"))
{
try
{
int newSize = int.Parse(argument[1]);
if ((newSize < 0) || (newSize > 100000))
throw new ArgumentOutOfRangeException("Log buffer size must be between 0 and 100000 bytes.");
else
bufferSize = newSize;
}
catch
{
ExitProgram(("Invalid log buffer size specified < " + argument[1] + " > "), exitCode: -1);
}
}
// specify log file (and enable logging) // specify log file (and enable logging)
else if (argument[0].StartsWith("lo")) else if (argument[0].StartsWith("lo"))
{ {
@ -525,6 +542,8 @@ namespace SimplySerial
Console.WriteLine(" -quiet don't print any application messages/errors to console"); Console.WriteLine(" -quiet don't print any application messages/errors to console");
Console.WriteLine(" -log:<logfile> Logs all output to the specified file."); Console.WriteLine(" -log:<logfile> Logs all output to the specified file.");
Console.WriteLine(" -logmode:MODE APPEND | OVERWRITE, default is OVERWRITE"); Console.WriteLine(" -logmode:MODE APPEND | OVERWRITE, default is OVERWRITE");
Console.WriteLine(" -logBuffer:VAL Number of bytes of data to buffer before writing to");
Console.WriteLine(" log file. Valid range is 0-100000.");
Console.WriteLine("\nPress CTRL-X to exit a running instance of SimplySerial.\n"); Console.WriteLine("\nPress CTRL-X to exit a running instance of SimplySerial.\n");
} }