示例#1
0
文件: RfIdhpr.cs 项目: khaikin/GymMgr
 public static RfIdhpr GetReader(int Port, int Baud)
 {
     if (_reader == null)
         _reader = new RfIdhpr(Port, Baud);
     return _reader;
 }
示例#2
0
文件: RfIdhpr.cs 项目: khaikin/GymMgr
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
                return;

            if (disposing)
            {
                prevCardSn = "";
                Disconnect();
                if (CardRead != null)
                {
                    var delegates = CardRead.GetInvocationList();
                    foreach (Delegate d in delegates)
                        CardRead -= (d as EventHandler<RfIdReadEvent>);
                }

                if (ReaderConnectionStateChanged != null)
                {
                    var delegates = ReaderConnectionStateChanged.GetInvocationList();
                    foreach (Delegate d in delegates)
                        ReaderConnectionStateChanged -= (d as EventHandler<RfIdConnectionEvent>);
                }

                _reader = null;
            }

            // Free any unmanaged objects here.
            //
            disposed = true;
        }
示例#3
0
文件: frmMain.cs 项目: khaikin/GymMgr
        /// <summary>
        /// Start polling the reader
        /// </summary>
        private void ActivateReader()
        {
            if (reader != null)
            {
                reader.Dispose();
                reader = null;
                return;

            }

            reader = RfIdhpr.GetReader(Port, Baud);
            reader.ReaderConnectionStateChanged += (o, e) => { UpdateStatus(e.Connected); };
            if (reader.Connect())
            {

                reader.CardRead += (o, e) =>
                                            {
                                                if (!string.IsNullOrEmpty(e.CardSN))
                                                    _dal.AddLogin(e.CardSN);
                                            };
                reader.StartPolling();
            }
            else
            {
                MessageBox.Show("קורא כרטיסים איננו מחובר", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (reader != null)
                {
                    reader.Dispose();
                    reader = null;
                }

            }
        }