Initial solution commit, working on command-line argument processing.

This commit is contained in:
Edward Wright 2019-05-28 23:31:15 -04:00
parent 80962c35de
commit 37fb2636c2
5 changed files with 239 additions and 0 deletions

6
SimplySerial/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SimplySerial")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimplySerial")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3c7db929-519c-44a3-a68f-2646cc595cae")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Threading;
namespace SimplySerial
{
class SimplySerial
{
static bool _continue = true;
static SerialPort _serialPort;
static void Main(string[] args)
{
ConsoleKeyInfo cki = new ConsoleKeyInfo();
Console.TreatControlCAsInput = true;
// default comspec values (will be overridden by command-line arguments)
string[] availablePorts = SerialPort.GetPortNames();
string port = string.Empty;
int baud = 9600;
Parity parity = Parity.None;
int dataBits = 8;
StopBits stopBits = StopBits.One;
if (availablePorts.Count() < 1)
ExitProgram("No COM ports detected.", -1);
else
port = availablePorts[0];
for(int i = 0; i < args.Count(); i++)
{
if ((args[i].ToLower()).StartsWith("-c"))
{
Console.WriteLine("PORT: {0}", args[i]);
}
if ((args[i].ToLower()).StartsWith("-b"))
{
Console.WriteLine("BAUD: {0}", args[i]);
}
if ((args[i].ToLower()).StartsWith("-p"))
{
Console.WriteLine("PARITY: {0}", args[i]);
}
if ((args[i].ToLower()).StartsWith("-d"))
{
Console.WriteLine("DATABITS: {0}", args[i]);
}
if ((args[i].ToLower()).StartsWith("-s"))
{
Console.WriteLine("STOPBITS: {0}", args[i]);
}
}
ExitProgram("That's All Folks!", 1);
_serialPort = new SerialPort("COM15", 9600, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
_serialPort.ReadTimeout = 1; //Timeout.Infinite;
_serialPort.WriteTimeout = 250; //Timeout.Infinite;
_serialPort.DtrEnable = true;
_serialPort.RtsEnable = true;
byte[] buffer = new byte[_serialPort.ReadBufferSize];
string rx = string.Empty;
int bytesRead = 0;
_serialPort.Open();
//while (!_serialPort.IsOpen)
//Thread.Sleep(25);
while (_continue)
{
if (Console.KeyAvailable)
{
cki = Console.ReadKey(true);
_serialPort.Write(Convert.ToString(cki.KeyChar));
}
try
{
//bytesRead = _serialPort.Read(buffer, 0, buffer.Length);
rx = _serialPort.ReadExisting();
}
catch (TimeoutException)
{
}
//if (bytesRead > 0)
if (rx.Length > 0)
{
//rx = Encoding.ASCII.GetString(buffer, 0, bytesRead);
Console.Write(rx);
}
}
_serialPort.Close();
}
static void ExitProgram(string message, int exitCode)
{
Console.WriteLine(message);
Console.WriteLine("\nPress any key to exit...");
while (!Console.KeyAvailable)
Thread.Sleep(25);
Environment.Exit(exitCode);
}
}
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3C7DB929-519C-44A3-A68F-2646CC595CAE}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SimplySerial</RootNamespace>
<AssemblyName>SimplySerial</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SimplySerial.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.645
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplySerial", "SimplySerial.csproj", "{3C7DB929-519C-44A3-A68F-2646CC595CAE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C7DB929-519C-44A3-A68F-2646CC595CAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C7DB929-519C-44A3-A68F-2646CC595CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C7DB929-519C-44A3-A68F-2646CC595CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C7DB929-519C-44A3-A68F-2646CC595CAE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {253902E3-B5BC-46E5-AA45-F17A6C84A16C}
EndGlobalSection
EndGlobal