示例#1
0
 private void Usbconnect_Click(object sender, RoutedEventArgs e)
 {
     if ((bool)usbconnect.IsChecked)
     {
         if (_usbServer.UsbConnect((bool)usbconnect.IsChecked, int.Parse(bytecnt.Text.Trim())))
         {
             usbstartrecv.IsEnabled = true;
             usbstoprecv.IsEnabled  = true;
         }
         else
         {
             usbconnect.IsChecked   = false;
             usbstartrecv.IsEnabled = false;
             usbstoprecv.IsEnabled  = false;
         }
     }
     else
     {
         if (!_usbServer.UsbConnect((bool)usbconnect.IsChecked, int.Parse(bytecnt.Text.Trim())))
         {
             _messageServer.AddWindowsMsg("设备断开失败,请重新上电!");
         }
         else
         {
             usbconnect.IsEnabled  = false;
             usbsavedata.IsEnabled = false;
             usbfilepath.IsEnabled = false;
         }
     }
 }
示例#2
0
        public bool UsbDeviceFinder()
        {
            for (int i = 0; i < _msgserver._usbDeviceList.Count; ++i)
            {
                _msgserver._usbDeviceList.RemoveAt(0);
            }

            _usbRegistries = UsbDevice.AllDevices.FindAll(_usbDeviceFinder);
            if (_usbRegistries.Count == 0)
            {
                _msgserver.AddWindowsMsg("Device Not Found");
                return(false);
            }
            else
            {
                foreach (UsbRegistry registry in _usbRegistries)
                {
                    _msgserver.AddDevice(_msgserver._usbDeviceList, registry.FullName);
                }
                return(true);
            }
        }