extens reader
This commit is contained in:
parent
3681ccc52a
commit
1b8f9132c3
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user