This commit is contained in:
BlubbFish 2011-10-09 19:32:38 +00:00
parent ce1cc70b15
commit 78c5424831
3 changed files with 89 additions and 11 deletions

View File

@ -18,7 +18,8 @@ namespace Matomat
private static LCDDisplay _createLCDDisplay() 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; return lcd;
} }

View File

@ -24,6 +24,8 @@ namespace Matomat
} }
class Input class Input
{ {
private class instance private class instance
{ {
public Input input; public Input input;
@ -37,13 +39,18 @@ namespace Matomat
} }
static List<instance> instances; static List<instance> instances;
private InputData data; private InputData data;
private RFIDReader rfid;
public Input()
{
rfid = new RFIDReader();
}
private void doWorkCard() private void doWorkCard()
{ {
while (true) while (true)
{ {
Thread.Sleep(1); Thread.Sleep(1);
data.id = rfid.getCardID();
data.type = InputData.types.Card; data.type = InputData.types.Card;
data.id = 3;
} }
} }
@ -66,7 +73,7 @@ namespace Matomat
while (!wtCard.IsAlive) ; while (!wtCard.IsAlive) ;
while (!wtCode.IsAlive) ; while (!wtCode.IsAlive) ;
DateTime time = DateTime.Now.AddSeconds(timeout); 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); Thread.Sleep(1);
} }
@ -77,7 +84,19 @@ namespace Matomat
internal InputData getProdInput(int timeout) 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() internal static Input getInstance()

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.IO.Ports;
namespace Matomat namespace Matomat
@ -12,9 +13,9 @@ namespace Matomat
private class instance private class instance
{ {
public LCDDisplay lCDDisplay; 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.lCDDisplay = lCDDisplay;
this.signature = signature; this.signature = signature;
@ -33,14 +34,32 @@ namespace Matomat
this.time = time; 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; static List<instance> instances;
private string port;
private Queue<Message> messages; private Queue<Message> messages;
private volatile bool _shouldStop; 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<Message>(); messages = new Queue<Message>();
Thread workerThread = new Thread(this.DoWork); Thread workerThread = new Thread(this.DoWork);
workerThread.Start(); workerThread.Start();
@ -69,6 +88,45 @@ namespace Matomat
private void display(string text, Status status) private void display(string text, Status status)
{ {
Console.WriteLine(text); 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 public enum Status
{ {
@ -102,11 +160,11 @@ namespace Matomat
this.anzeige(text, status, time); this.anzeige(text, status, time);
} }
internal static LCDDisplay getInstance(string port) internal static LCDDisplay getInstance(Comport port)
{ {
if (instances == null) if (instances == null)
instances = new List<instance>(); instances = new List<instance>();
double signature = Helper.Serialize(port); string signature = Helper.Serialize(port);
foreach (instance i in instances) foreach (instance i in instances)
{ {
if (i.signature == signature) if (i.signature == signature)