diff --git a/Matomat/Factory.cs b/Matomat/Factory.cs index 44e75bf..8d7feb8 100644 --- a/Matomat/Factory.cs +++ b/Matomat/Factory.cs @@ -18,7 +18,8 @@ namespace Matomat private static LCDDisplay _createLCDDisplay() { - LCDDisplay lcd = LCDDisplay.getInstance("lpd1"); + 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; } diff --git a/Matomat/Input.cs b/Matomat/Input.cs index 5223c38..8bfc220 100644 --- a/Matomat/Input.cs +++ b/Matomat/Input.cs @@ -24,6 +24,8 @@ namespace Matomat } class Input { + + private class instance { public Input input; @@ -37,13 +39,18 @@ namespace Matomat } static List instances; private InputData data; + private RFIDReader rfid; + public Input() + { + rfid = new RFIDReader(); + } private void doWorkCard() { while (true) { Thread.Sleep(1); + data.id = rfid.getCardID(); data.type = InputData.types.Card; - data.id = 3; } } @@ -66,7 +73,7 @@ namespace Matomat while (!wtCard.IsAlive) ; while (!wtCode.IsAlive) ; DateTime time = DateTime.Now.AddSeconds(timeout); - while (time.Ticks < DateTime.Now.Ticks || data.type == InputData.types.None) + while (time.Ticks > DateTime.Now.Ticks && data.type == InputData.types.None) { Thread.Sleep(1); } @@ -77,7 +84,19 @@ namespace Matomat internal InputData getProdInput(int timeout) { - throw new NotImplementedException(); + if (timeout == 0) + timeout = Int32.MaxValue; + data = new InputData(); + Thread wtCode = new Thread(this.doWorkCode); + wtCode.Start(); + while (!wtCode.IsAlive) ; + DateTime time = DateTime.Now.AddSeconds(timeout); + while (time.Ticks > DateTime.Now.Ticks && data.type == InputData.types.None) + { + Thread.Sleep(1); + } + wtCode.Abort(); + return data; } internal static Input getInstance() diff --git a/Matomat/LCDDisplay.cs b/Matomat/LCDDisplay.cs index bae7fc4..e163f95 100644 --- a/Matomat/LCDDisplay.cs +++ b/Matomat/LCDDisplay.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using System.IO.Ports; namespace Matomat @@ -12,9 +13,9 @@ namespace Matomat private class instance { public LCDDisplay lCDDisplay; - public double signature; + public string signature; - public instance(LCDDisplay lCDDisplay, double signature) + public instance(LCDDisplay lCDDisplay, string signature) { this.lCDDisplay = lCDDisplay; this.signature = signature; @@ -33,14 +34,32 @@ 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 string port; private Queue messages; private volatile bool _shouldStop; + private SerialPort serialPort; - public LCDDisplay(string port) + public LCDDisplay(Comport port) { - this.port = port; + this.serialPort = new SerialPort(port.port, port.bautrate, port.parity, port.databits, port.stopbits); + this.serialPort.Open(); messages = new Queue(); Thread workerThread = new Thread(this.DoWork); workerThread.Start(); @@ -69,6 +88,45 @@ namespace Matomat private void display(string text, Status status) { Console.WriteLine(text); + this.displayClear(); + byte[] btext = text.ToCharArray("ÄÖÜäöü", new byte[] { 0xE1, 0xEF, 0xF5, 0xE1, 0xEF, 0xF5 }); + byte[] upper; + byte[] lower; + if (text.Length > 80) + { + upper = btext.Substring(0, 80); + lower = btext.Substring(80); + } + else + { + upper = btext; + lower = new byte[0]; + } + this.displayEscCode("GTO0@"); + this.displayCode(upper); + this.displayEscCode("GTO2@"); + this.displayCode(lower); + } + + private void displayClear() + { + this.displayEscCode("GTO0@"); + this.displayCode(new byte[] { 0x0c }); + this.displayEscCode("GTO2@"); + this.displayCode(new byte[] { 0x0c }); + this.displayEscCode("GTO0@"); + } + + private void displayCode(byte[] p) + { + this.serialPort.Write(p, 0, p.Length); + } + + private void displayEscCode(string code) + { + this.displayCode(new byte[] { 0x1b }); + this.serialPort.Write(code); + this.displayCode(new byte[] { 0x0d }); } public enum Status { @@ -102,11 +160,11 @@ namespace Matomat this.anzeige(text, status, time); } - internal static LCDDisplay getInstance(string port) + internal static LCDDisplay getInstance(Comport port) { if (instances == null) instances = new List(); - double signature = Helper.Serialize(port); + string signature = Helper.Serialize(port); foreach (instance i in instances) { if (i.signature == signature)