diff --git a/Matomat/App.config b/Matomat/App.config new file mode 100644 index 0000000..f7ae6c7 --- /dev/null +++ b/Matomat/App.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Matomat/BarcodeReader.cs b/Matomat/BarcodeReader.cs index b85a97c..15879fb 100644 --- a/Matomat/BarcodeReader.cs +++ b/Matomat/BarcodeReader.cs @@ -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(); } } } diff --git a/Matomat/Config.cs b/Matomat/Config.cs new file mode 100644 index 0000000..7d53baf --- /dev/null +++ b/Matomat/Config.cs @@ -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 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(); + 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; } + } +} diff --git a/Matomat/Factory.cs b/Matomat/Factory.cs index 8d7feb8..034e940 100644 --- a/Matomat/Factory.cs +++ b/Matomat/Factory.cs @@ -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); } } } diff --git a/Matomat/Helper.cs b/Matomat/Helper.cs index fffc7d4..1e22f4d 100644 --- a/Matomat/Helper.cs +++ b/Matomat/Helper.cs @@ -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 { diff --git a/Matomat/Input.cs b/Matomat/Input.cs index b1f5297..e847171 100644 --- a/Matomat/Input.cs +++ b/Matomat/Input.cs @@ -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; } diff --git a/Matomat/LCDDisplay.cs b/Matomat/LCDDisplay.cs index 90ebae6..89b82bf 100644 --- a/Matomat/LCDDisplay.cs +++ b/Matomat/LCDDisplay.cs @@ -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 instances; private Queue 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(); - 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; } diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj index f4be0e5..ee14549 100644 --- a/Matomat/Matomat.csproj +++ b/Matomat/Matomat.csproj @@ -49,6 +49,7 @@ + @@ -68,6 +69,9 @@ PreserveNewest + + +