コード例 #1
0
 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();
                 }
             }
         }
     }
 }
コード例 #2
0
        public static void ReleaseDevices()
        {
            try
            {
                if (Device != null)
                {
                    Device.DisconnectReader();
                    Device.Dispose();
                }

                if (GpioCardObject != null)
                {
                    GpioCardObject.CloseSerialPort();
                    GpioCardObject = new GpioCardLib();
                }
            }
            catch
            {
            }
        }