public static RfIdhpr GetReader(int Port, int Baud) { if (_reader == null) _reader = new RfIdhpr(Port, Baud); return _reader; }
// 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; }
/// <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; } } }