public rfidPluggedInfo[] getRFIDpluggedDevice() { try { ArrayList listdev = new ArrayList(); //string[] ports = System.IO.Ports.SerialPort.GetPortNames(); List <string> ports = GetDevicePortCom(); foreach (string s in ports) { RfidReader deviceForDiscover = new RfidReader(); deviceForDiscover.NotifyEvent += new SDK_SC_RfidReader.NotifyHandlerDelegate(deviceForDiscover_NotifyEvent); deviceForDiscover.ConnectReader(s); eventEndDiscover.WaitOne(500, false); if (deviceForDiscover.IsConnected) { rfidPluggedInfo tmpdev = new rfidPluggedInfo(); if (!deviceForDiscover.HardwareVersion.Contains(".")) { break; // for modem } string hw = deviceForDiscover.HardwareVersion.Substring(0, deviceForDiscover.HardwareVersion.IndexOf('.')); tmpdev.deviceType = (DeviceType)int.Parse(hw); tmpdev.SerialRFID = deviceForDiscover.SerialNumber; tmpdev.portCom = deviceForDiscover.StrCom; listdev.Add(tmpdev); deviceForDiscover.Dispose(); } } if (listdev.Count > 0) { int nIndex = 0; rfidPluggedInfo[] arrayDev = new rfidPluggedInfo[listdev.Count]; foreach (rfidPluggedInfo dev in listdev) { arrayDev[nIndex++] = dev; } return(arrayDev); } else { return(null); } } catch (Exception exp) { ErrorMessage.ExceptionMessageBox.Show(exp); return(null); } }
public static void ReleaseDevices() { try { if (Device != null) { Device.DisconnectReader(); Device.Dispose(); } if (GpioCardObject != null) { GpioCardObject.CloseSerialPort(); GpioCardObject = new GpioCardLib(); } } catch { } }
public void Dispose() { RfidReader?.Dispose(); }