diff --git a/SimplySerial/App.config b/SimplySerial/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/SimplySerial/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SimplySerial/Properties/AssemblyInfo.cs b/SimplySerial/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ed3847c --- /dev/null +++ b/SimplySerial/Properties/AssemblyInfo.cs @@ -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")] diff --git a/SimplySerial/SimplySerial.cs b/SimplySerial/SimplySerial.cs new file mode 100644 index 0000000..2fce8dc --- /dev/null +++ b/SimplySerial/SimplySerial.cs @@ -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); + } + } +} diff --git a/SimplySerial/SimplySerial.csproj b/SimplySerial/SimplySerial.csproj new file mode 100644 index 0000000..d41e963 --- /dev/null +++ b/SimplySerial/SimplySerial.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {3C7DB929-519C-44A3-A68F-2646CC595CAE} + Exe + SimplySerial + SimplySerial + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SimplySerial/SimplySerial.sln b/SimplySerial/SimplySerial.sln new file mode 100644 index 0000000..90c954b --- /dev/null +++ b/SimplySerial/SimplySerial.sln @@ -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