diff --git a/.gitignore b/.gitignore index 5edc7e5..0330688 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ docs/ PyramidNETRS232Installer/bin/ PyramidNETRS232Installer/obj/ packages/ +PyramidNETRS232_TestApp_Simple/bin/ +PyramidNETRS232_TestApp_Simple/obj/ diff --git a/Pyramid.sln b/Pyramid.sln index 3cd42f2..77925f0 100644 --- a/Pyramid.sln +++ b/Pyramid.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PyramidNETRS232_Test", "API EndProject Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "PyramidNETRS232Installer", "PyramidNETRS232Installer\PyramidNETRS232Installer.wixproj", "{86531783-173C-45AE-B085-1A3B89544831}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PyramidNETRS232_TestApp_Simple", "PyramidNETRS232_TestApp_Simple\PyramidNETRS232_TestApp_Simple.csproj", "{4B9840DE-6444-405E-A866-FB2075F13426}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,16 @@ Global {86531783-173C-45AE-B085-1A3B89544831}.Release|Mixed Platforms.Build.0 = Release|x86 {86531783-173C-45AE-B085-1A3B89544831}.Release|x86.ActiveCfg = Release|x86 {86531783-173C-45AE-B085-1A3B89544831}.Release|x86.Build.0 = Release|x86 + {4B9840DE-6444-405E-A866-FB2075F13426}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Debug|x86.ActiveCfg = Debug|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Release|Any CPU.Build.0 = Release|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {4B9840DE-6444-405E-A866-FB2075F13426}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PyramidNETRS232_TestApp_Simple/App.config b/PyramidNETRS232_TestApp_Simple/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/PyramidNETRS232_TestApp_Simple/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PyramidNETRS232_TestApp_Simple/Program.cs b/PyramidNETRS232_TestApp_Simple/Program.cs new file mode 100644 index 0000000..a368f64 --- /dev/null +++ b/PyramidNETRS232_TestApp_Simple/Program.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PyramidNETRS232_TestApp_Simple +{ + class Program + { + /// + /// Dead simple demo. The error handling and extra features have been omitted for simplicity. + /// + /// + static void Main(string[] args) + { + Console.WriteLine("Enter port name in format: COMX"); + + var port = Console.ReadLine(); + + SingleBillValidator.Instance.Connect(port); + + Console.WriteLine("Connected on port {0}", port); + + Console.WriteLine("Press ESC to stop"); + do + { + while (!Console.KeyAvailable) { } + + } while (Console.ReadKey(true).Key != ConsoleKey.Escape); + + Console.WriteLine("Quitting..."); + + SingleBillValidator.Instance.Disconnect(); + } + } +} diff --git a/PyramidNETRS232_TestApp_Simple/Properties/AssemblyInfo.cs b/PyramidNETRS232_TestApp_Simple/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fc89d77 --- /dev/null +++ b/PyramidNETRS232_TestApp_Simple/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("PyramidNETRS232_TestApp_Simple")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PyramidNETRS232_TestApp_Simple")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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("4b7009da-2a03-474a-862a-b1692196505f")] + +// 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/PyramidNETRS232_TestApp_Simple/PyramidNETRS232_TestApp_Simple.csproj b/PyramidNETRS232_TestApp_Simple/PyramidNETRS232_TestApp_Simple.csproj new file mode 100644 index 0000000..b2e9af5 --- /dev/null +++ b/PyramidNETRS232_TestApp_Simple/PyramidNETRS232_TestApp_Simple.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {4B9840DE-6444-405E-A866-FB2075F13426} + Exe + Properties + PyramidNETRS232_TestApp_Simple + PyramidNETRS232_TestApp_Simple + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {735220bb-d8e8-4e21-80d9-aea6e41b13ed} + PyramidNETRS232 + + + + + \ No newline at end of file diff --git a/PyramidNETRS232_TestApp_Simple/SingleBillValidator.cs b/PyramidNETRS232_TestApp_Simple/SingleBillValidator.cs new file mode 100644 index 0000000..bb16fe3 --- /dev/null +++ b/PyramidNETRS232_TestApp_Simple/SingleBillValidator.cs @@ -0,0 +1,60 @@ +using PyramidNETRS232; +using System; + +namespace PyramidNETRS232_TestApp_Simple +{ + public class SingleBillValidator + { + private static volatile SingleBillValidator instance; + private static object syncRoot = new Object(); + + private PyramidAcceptor validator { get; set; } + + public RS232Config Config { get; set; } + + public static SingleBillValidator Instance + { + get + { + if (instance == null) + { + lock (syncRoot) + { + if (instance == null) + { + instance = new SingleBillValidator(); + } + } + } + + return instance; + } + } + + private SingleBillValidator() + { + + } + + public void Connect(string port) + { + Config = new RS232Config(port, false); + validator = new PyramidAcceptor(Config); + + validator.OnCredit += validator_OnCredit; + + validator.Connect(); + } + + void validator_OnCredit(object sender, CreditArgs e) + { + Console.WriteLine("Credited bill#: {0}", e.Index); + } + + public void Disconnect() + { + if (validator != null) + validator.Close(); + } + } +}