Skip to content

Commit

Permalink
Add dead simple sample command line app that uses the singleton approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Todd committed Sep 21, 2015
1 parent 43528a9 commit 4eeb974
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ docs/
PyramidNETRS232Installer/bin/
PyramidNETRS232Installer/obj/
packages/
PyramidNETRS232_TestApp_Simple/bin/
PyramidNETRS232_TestApp_Simple/obj/
12 changes: 12 additions & 0 deletions Pyramid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions PyramidNETRS232_TestApp_Simple/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
37 changes: 37 additions & 0 deletions PyramidNETRS232_TestApp_Simple/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Dead simple demo. The error handling and extra features have been omitted for simplicity.
/// </summary>
/// <param name="args"></param>
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();
}
}
}
36 changes: 36 additions & 0 deletions PyramidNETRS232_TestApp_Simple/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{4B9840DE-6444-405E-A866-FB2075F13426}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PyramidNETRS232_TestApp_Simple</RootNamespace>
<AssemblyName>PyramidNETRS232_TestApp_Simple</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SingleBillValidator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Apex7000_BillValidator\PyramidNETRS232.csproj">
<Project>{735220bb-d8e8-4e21-80d9-aea6e41b13ed}</Project>
<Name>PyramidNETRS232</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
60 changes: 60 additions & 0 deletions PyramidNETRS232_TestApp_Simple/SingleBillValidator.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 4eeb974

Please sign in to comment.