コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: coolgate/CardReaderService
        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);
        }
コード例 #4
0
        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();
        }