public void TestCardReader() { var reader = new CardReader(); reader.OpenDevice(); var count = 10; var sleepTime = 1000; while (count > 0) { var uid = reader.ReadUid(); if (uid != "") { Console.WriteLine(uid); reader.Beep(100); count--; sleepTime = 3000; } else { sleepTime = 1000; } Thread.Sleep(sleepTime); } reader.CloseDevice(); }
public void TestReadForever() { var reader = new CardReader(); reader.OnReadCardUid += new CardReader.ReadCardUidHandler((sender, e) => { Console.WriteLine("Card ID: " + e.Uid); }); reader.OpenDevice(); reader.ReadForever(); Thread.Sleep(10000); reader.StopReadForever(); reader.CloseDevice(); }
public bool Start() { _reader = new CardReader(); _reader.HoldTime = 2000; _reader.ReadInterval = 1000; // Simple Logger _reader.OnReadCardUid += (sender, e) => { var msg = string.Format("Read Card, UID = {0}", e.Uid); Console.WriteLine(msg); _log.Info(msg); }; // NetMQ Serive _pubsock = new PublisherSocket(pubAddress); _reader.OnReadCardUid += (sender, e) => { var ok = _pubsock.SendMoreFrame(_channel).TrySendFrame(e.Uid); if (ok) { var msg = string.Format("Publish Message: Card UID = {0}", e.Uid); _log.Debug(msg); } }; // WebSocket Service _socketServer = new WebSocketServer(socketServerAddress); _socketServer.AddWebSocketService <CardReaderWebSocketService>("/CardReader"); _reader.OnReadCardUid += (sender, e) => { if (_socketServer.IsListening) { var msg = string.Format("{{\"uid\": \"{0}\"}}", e.Uid); _socketServer.WebSocketServices["/CardReader"].Sessions.Broadcast(msg); } }; _socketServer.Start(); Console.WriteLine("Press CTRL+C to stop ..."); _reader.OpenDevice(); _reader.ReadForever(); return(true); }
static void Main(string[] args) { var reader = new CardReader(); reader.HoldTime = 2000; reader.ReadInterval = 1000; reader.OnReadCardUid += (sender, e) => { Console.WriteLine("Card UID: " + e.Uid); }; Console.WriteLine("Press ENTER to stop ..."); reader.OpenDevice(); reader.ReadForever(); Console.Read(); reader.StopReadForever(); reader.CloseDevice(); }