public static void FindAndConnectDevice() { lock (thisLock) { //Connect RFID List <string> comPortList = new List <string>(System.IO.Ports.SerialPort.GetPortNames()); if ((comPortList != null) && (comPortList.Count > 0)) { foreach (string comPort in comPortList) { RfidReader tmpReader = new RfidReader(); tmpReader.NotifyEvent += deviceForDiscover_NotifyEvent; tmpReader.ConnectReader(comPort); eventEndDiscover.WaitOne(500, false); if (tmpReader.IsConnected) { Device = tmpReader; Device.NotifyEvent += Device_NotifyEvent; InitDeviceList(tmpReader.SerialNumber); LastScanAccessTypeName = AccessType.Manual; FireEvent(DeviceConnected, tmpReader.SerialNumber, 0); } else { tmpReader.DisconnectReader(); tmpReader.Dispose(); } } } } }
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); } }