Reader Gogogogo
This commit is contained in:
parent
1b8f9132c3
commit
77ec113e0d
7
Matomat/App.config
Normal file
7
Matomat/App.config
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="com_display" value="COM1" />
|
||||
<add key="com_rfid" value="COM2" />
|
||||
</appSettings>
|
||||
</configuration>
|
@ -2,14 +2,28 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Matomat
|
||||
{
|
||||
class BarcodeReader
|
||||
{
|
||||
private TextReader r;
|
||||
internal long getCodeID()
|
||||
{
|
||||
return 4029764001807;
|
||||
r = Console.In;
|
||||
string str = r.ReadLine();
|
||||
try
|
||||
{
|
||||
return Convert.ToInt64(str);
|
||||
}
|
||||
catch (Exception) { }
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal void Abort()
|
||||
{
|
||||
r.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
58
Matomat/Config.cs
Normal file
58
Matomat/Config.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Matomat
|
||||
{
|
||||
class Config
|
||||
{
|
||||
private class instance
|
||||
{
|
||||
public Config config;
|
||||
public string signature;
|
||||
|
||||
public instance(Config config, string signature)
|
||||
{
|
||||
this.config = config;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
static List<instance> instances;
|
||||
private AppSettingsReader config;
|
||||
|
||||
public Config()
|
||||
{
|
||||
this.config = new AppSettingsReader();
|
||||
loadFile();
|
||||
}
|
||||
private void loadFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.com_display = (string)config.GetValue("com_display", typeof(string));
|
||||
this.com_rfid = (string)config.GetValue("com_rfid", typeof(string));
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
internal static Config getInstance(string file)
|
||||
{
|
||||
if (instances == null)
|
||||
instances = new List<instance>();
|
||||
foreach (instance i in instances)
|
||||
{
|
||||
if (i.signature == file)
|
||||
return i.config;
|
||||
}
|
||||
instance instance = new instance(new Config(), file);
|
||||
instances.Add(instance);
|
||||
return instance.config;
|
||||
}
|
||||
|
||||
public string com_display { get; set; }
|
||||
public string com_rfid { get; set; }
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ namespace Matomat
|
||||
{
|
||||
static LCDDisplay lcd_i = null;
|
||||
static Input inp_i = null;
|
||||
static Config con_i = null;
|
||||
internal static LCDDisplay getLCDDisplay()
|
||||
{
|
||||
if (lcd_i == null)
|
||||
@ -18,9 +19,7 @@ namespace Matomat
|
||||
|
||||
private static LCDDisplay _createLCDDisplay()
|
||||
{
|
||||
LCDDisplay.Comport comport = new LCDDisplay.Comport("COM1",19200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
|
||||
LCDDisplay lcd = LCDDisplay.getInstance(comport);
|
||||
return lcd;
|
||||
return LCDDisplay.getInstance(Factory.getConfig().com_display);
|
||||
}
|
||||
|
||||
internal static Input getInput()
|
||||
@ -32,8 +31,18 @@ namespace Matomat
|
||||
|
||||
private static Input _createInput()
|
||||
{
|
||||
Input inp = Input.getInstance();
|
||||
return inp;
|
||||
return Input.getInstance();
|
||||
}
|
||||
internal static Config getConfig()
|
||||
{
|
||||
if (con_i == null)
|
||||
con_i = Factory._createConfig("App.config");
|
||||
return con_i;
|
||||
}
|
||||
|
||||
private static Config _createConfig(string file)
|
||||
{
|
||||
return Config.getInstance(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,7 @@ namespace Matomat
|
||||
{
|
||||
class Helper
|
||||
{
|
||||
internal static string Serialize(LCDDisplay.Comport comport)
|
||||
{
|
||||
return comport.port + comport.bautrate.ToString() + comport.databits.ToString() + comport.parity.ToString() + comport.stopbits.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
public static class String
|
||||
{
|
||||
|
@ -51,10 +51,10 @@ namespace Matomat
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
char k = 'k';
|
||||
if (k == 'r')
|
||||
long id = rfid.getCardID();
|
||||
if (id != 0)
|
||||
{
|
||||
data.id = rfid.getCardID();
|
||||
data.id = id;
|
||||
data.type = InputData.types.Card;
|
||||
}
|
||||
}
|
||||
@ -65,11 +65,10 @@ namespace Matomat
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
char k = Console.ReadKey(false).KeyChar;
|
||||
Console.WriteLine();
|
||||
if (k == 'b')
|
||||
long id = code.getCodeID();
|
||||
if (id != 0)
|
||||
{
|
||||
data.id = code.getCodeID();
|
||||
data.id = id;
|
||||
data.type = InputData.types.Prod;
|
||||
}
|
||||
}
|
||||
@ -92,6 +91,8 @@ namespace Matomat
|
||||
}
|
||||
wtCard.Abort();
|
||||
wtCode.Abort();
|
||||
rfid.Abort();
|
||||
code.Abort();
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -109,6 +110,7 @@ namespace Matomat
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
wtCode.Abort();
|
||||
code.Abort();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -34,32 +34,15 @@ namespace Matomat
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
public class Comport
|
||||
{
|
||||
public string port;
|
||||
public int bautrate;
|
||||
public Parity parity;
|
||||
public int databits;
|
||||
public StopBits stopbits;
|
||||
|
||||
public Comport(string port, int bautrate, Parity parity, int databits, StopBits stopbits)
|
||||
{
|
||||
this.port = port;
|
||||
this.bautrate = bautrate;
|
||||
this.parity = parity;
|
||||
this.databits = databits;
|
||||
this.stopbits = stopbits;
|
||||
}
|
||||
}
|
||||
static List<instance> instances;
|
||||
private Queue<Message> messages;
|
||||
private volatile bool _shouldStop;
|
||||
private SerialPort serialPort;
|
||||
private bool disable = false;
|
||||
|
||||
public LCDDisplay(Comport port)
|
||||
public LCDDisplay(string port)
|
||||
{
|
||||
this.serialPort = new SerialPort(port.port, port.bautrate, port.parity, port.databits, port.stopbits);
|
||||
this.serialPort = new SerialPort(port, 19200, Parity.None, 8, StopBits.One);
|
||||
try
|
||||
{
|
||||
this.serialPort.Open();
|
||||
@ -148,6 +131,10 @@ namespace Matomat
|
||||
|
||||
private void createChars()
|
||||
{
|
||||
this.displayEscCode("GTO0@");
|
||||
this.displayEscCode("UDC0GH_H_HG@");
|
||||
|
||||
this.displayEscCode("GTO2@");
|
||||
this.displayEscCode("UDC0GH_H_HG@");
|
||||
}
|
||||
|
||||
@ -192,17 +179,16 @@ namespace Matomat
|
||||
this.anzeige(text, status, time);
|
||||
}
|
||||
|
||||
internal static LCDDisplay getInstance(Comport port)
|
||||
internal static LCDDisplay getInstance(string port)
|
||||
{
|
||||
if (instances == null)
|
||||
instances = new List<instance>();
|
||||
string signature = Helper.Serialize(port);
|
||||
foreach (instance i in instances)
|
||||
{
|
||||
if (i.signature == signature)
|
||||
if (i.signature == port)
|
||||
return i.lCDDisplay;
|
||||
}
|
||||
instance instance = new instance(new LCDDisplay(port),signature);
|
||||
instance instance = new instance(new LCDDisplay(port), port);
|
||||
instances.Add(instance);
|
||||
return instance.lCDDisplay;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Automat.cs" />
|
||||
<Compile Include="BarcodeReader.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Factory.cs" />
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Input.cs" />
|
||||
@ -68,6 +69,9 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</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.
|
||||
|
@ -38,6 +38,7 @@ namespace Matomat
|
||||
"² Produkt wurde nich gefunden ²"+
|
||||
"² EAN13: "+(this.GetProdId().ToString()+" unbekannt").PadRight(29,' ')+" ²"+
|
||||
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5);
|
||||
System.Threading.Thread.Sleep(4500);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -2,14 +2,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using RfidClass;
|
||||
|
||||
namespace Matomat
|
||||
{
|
||||
class RFIDReader
|
||||
{
|
||||
private RFIDReaderClass r;
|
||||
public RFIDReader()
|
||||
{
|
||||
r = new RFIDReaderClass(Factory.getConfig().com_rfid);
|
||||
}
|
||||
internal long getCardID()
|
||||
{
|
||||
return 0xFFFFFFFF;
|
||||
try
|
||||
{
|
||||
return r.readKey();
|
||||
}
|
||||
catch (Exception) //e)
|
||||
{
|
||||
//Console.WriteLine(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal void Abort()
|
||||
{
|
||||
r.abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user