From 1b8f9132c3030e00147cf74ded18e89f096522de Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 25 Oct 2011 20:01:41 +0000 Subject: [PATCH] extens reader --- RFIDIdReader/RFIDIdReader/Program.cs | 15 ++++++++++++--- RFIDIdReader/RfidClass/RFIDReaderClass.cs | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/RFIDIdReader/RFIDIdReader/Program.cs b/RFIDIdReader/RFIDIdReader/Program.cs index 48ea2dd..454b4ca 100644 --- a/RFIDIdReader/RFIDIdReader/Program.cs +++ b/RFIDIdReader/RFIDIdReader/Program.cs @@ -13,7 +13,7 @@ namespace RFIDIdReader private static bool _stop = false; static void Main(string[] args) { - r = new RFIDReaderClass("COM1"); + r = new RFIDReaderClass("COM26"); Thread t = new Thread(reader); t.Start(); while (!t.IsAlive) ; @@ -31,8 +31,17 @@ namespace RFIDIdReader { while (!_stop) { - long id = r.readKey(); - Console.WriteLine(id); + try + { + long id = r.readKey(); + Console.WriteLine(id); + r.reset(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + Thread.Sleep(3000); } } diff --git a/RFIDIdReader/RfidClass/RFIDReaderClass.cs b/RFIDIdReader/RfidClass/RFIDReaderClass.cs index 0a44034..8065632 100644 --- a/RFIDIdReader/RfidClass/RFIDReaderClass.cs +++ b/RFIDIdReader/RfidClass/RFIDReaderClass.cs @@ -16,7 +16,7 @@ namespace RfidClass public RFIDReaderClass(string com) { this.t = new Thread(this.reader); - s = new SerialPort(com, 9600, Parity.None, 8, StopBits.One); + s = new SerialPort(com, 115200, Parity.None, 8, StopBits.One); } private void reader() @@ -65,16 +65,18 @@ namespace RfidClass public long readKey() { + this.e = null; this.t = new Thread(this.reader); this.id = 0; this._stop = false; try { - this.s.Open(); + if(!s.IsOpen) + this.s.Open(); } catch (Exception exeption) { - //throw exeption; + throw exeption; } this.t.Start(); while (!this.t.IsAlive) ; @@ -84,6 +86,7 @@ namespace RfidClass { this._stop = true; } + Thread.Sleep(10); } if (this.e != null) { @@ -95,6 +98,14 @@ namespace RfidClass public void abort() { this._stop = true; + this.reset(); + this.s.Close(); + } + + public void reset() + { + if (s.IsOpen) + this.s.Write("9"); } } }