Пример #1
0
        public void InitUsb()
        {
            UsbPort = new FeUsb();

            UsbPort.AddEventListener(0, this, FeUsbListenerConst.FEUSB_CONNECT_EVENT);
            UsbPort.AddEventListener(0, this, FeUsbListenerConst.FEUSB_DISCONNECT_EVENT);

            try
            {
                UsbPort.ScanAndOpen(FeUsbScanSearch.SCAN_ALL, null);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }

            for (var i = 0; i < UsbPort.ScanListSize; i++)
            {
                AddDevice(FeHexConvert.HexStringToInteger(UsbPort.GetScanListPara(i, "Device-ID")));
            }

            Interval           = new Timer();
            Interval.Interval  = 1000;
            Interval.Elapsed  += (s, e) => { ReadDevices(); };
            Interval.AutoReset = false;

            ReadDevices();
        }
Пример #2
0
        //Init usbport  with Events(connect/disconect)
        public void USBInit()
        {
            long   nDeviceID = 0;
            String sDeviceID;

            UsbPort = new FeUsb();

            UsbPort.AddEventListener(0, (FeUsbListener)this, FeUsbListenerConst.FEUSB_CONNECT_EVENT);
            UsbPort.AddEventListener(0, (FeUsbListener)this, FeUsbListenerConst.FEUSB_DISCONNECT_EVENT);

            try
            {
                UsbPort.ScanAndOpen(FeUsbScanSearch.SCAN_ALL, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


            for (int i = 0; i < UsbPort.ScanListSize; i++)
            {
                sDeviceID = UsbPort.GetScanListPara(i, "Device-ID");
                if (sDeviceID.Length % 2 != 0)
                {
                    sDeviceID = "0" + sDeviceID;
                }
                nDeviceID = FeHexConvert.HexStringToLong(sDeviceID);
                AddDevice(nDeviceID);
            }
        }