コード例 #1
0
 public bool SetCurrentDevice(String deviceInstance)
 {
     foreach (var model in DeviceViewModelList)
     {
         if (model.DeviceInstance == deviceInstance)
         {
             CurrentDevice = model;
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        void DeviceManager_DeviceChanged(DeviceChangedEventArgs eventArgs)
        {
            Trace.WriteLine(String.Format("*** MainWindow.DeviceManager_DeviceChanged(): {0}: {1}, {2}({3})",
                                          eventArgs.Event, eventArgs.DeviceId, Thread.CurrentThread.Name, Thread.CurrentThread.GetHashCode()));
            String logStr = eventArgs.Event + ": " + eventArgs.DeviceId + "\r\n";;

            //LogTextBox.AppendText(logStr);

            //TODO: Fix Device Arrival/Removal messages coming in the wrong order!

            if (eventArgs.Event == DeviceChangeEvent.DeviceArrival)
            {
                DeviceManager.Refresh();
                if (CurrentDevice.IsNull && _PreviousDevice != null && _PreviousDevice.DeviceInstance == eventArgs.DeviceId)
                {
                    DeviceViewModelList.Add(_PreviousDevice);
                    CurrentDevice   = _PreviousDevice;
                    _PreviousDevice = null;
                }
                else
                {
                    var device = DeviceManager.DeviceClassMgrs.SelectMany(mgr => mgr.Devices).Single(dev => dev.DeviceInstanceId == eventArgs.DeviceId);
                    DeviceViewModelList.Add(new DeviceViewModel(device));
                }
            }
            else if (eventArgs.Event == DeviceChangeEvent.DeviceRemoval)
            {
                if (CurrentDevice.DeviceInstance == eventArgs.DeviceId)
                {
                    _PreviousDevice = CurrentDevice;
                    CurrentDevice   = new DeviceViewModel();
                }

                var devModel = DeviceViewModelList.SingleOrDefault(model => model.DeviceInstance == eventArgs.DeviceId);
                DeviceViewModelList.Remove(devModel);

                DeviceManager.Refresh();
            }

//            else if (MainMenuItem_File_TrackUsbPort.Checked)
//            {
//                _CurrentDevice = FindDeviceByPort(LastPort);
//                CurrentApi = LoadDeviceApis(_CurrentDevice);
//
//                if (_CurrentDevice != null)
//                {
//                    logStr = String.Format("Track USB Port(Hub{0},Port{1}): AutoSelect \"{2}\".\r\n", _CurrentDevice.UsbHub.Index, _CurrentDevice.UsbPort, _CurrentDevice.ToString());
//                    LogTextBox.AppendText(logStr);
//                }
//            }

//                        UpdateStatus();
        }
コード例 #3
0
//        private blfwkdll.Updater.UpdaterOperationProgressDelegate ProgressCallback =
//            new blfwkdll.Updater.UpdaterOperationProgressDelegate(UpdaterProgress);

        public UpdaterViewModel(DeviceViewModel device)
            : base(device)
        {
            ImageFileModel = null;
            var progress = new Progress <blfwkdll.Updater.UpdaterOperationProgressData>(UpdaterProgress);

            UpdateCommand = new UpdaterAsyncCommand(token => Update(this, progress, token));

            BackdoorKey = Properties.Settings.Default.BackdoorKey;

            Status = "Ready";
            Value  = 0;
            Total  = 100;
        }
コード例 #4
0
        private void InitDeviceList()
        {
            CurrentDevice = new DeviceViewModel();

            foreach (var dev in HidDeviceClass.Instance.Devices)
            {
                DeviceViewModelList.Add(new DeviceViewModel(dev));
            }

            foreach (var dev in SerialPortDeviceClass.Instance.Devices)
            {
                DeviceViewModelList.Add(new DeviceViewModel(dev));
            }
        }
コード例 #5
0
        public BootloaderViewModel(DeviceViewModel device)
        {
            DeviceModel = device;
            // Creating a Bootloader object entails Pinging the peripheral.
            // We don't want to talk to the device until it becomes selected.
            // That way, we will not try to talk to devices that are not
            // known to be Kinestis Bootloader devices, and we will not
            // shut down alternate peripherals on a given Kinetis Bootloader
            // device.
            Updater = null;

            if (DeviceModel != null)
            {
                if (DeviceModel.IsSerial)
                {
                    IsConnectedTimer          = new System.Windows.Threading.DispatcherTimer();
                    IsConnectedTimer.Tick    += new EventHandler(IsConnectedTimer_Tick);
                    IsConnectedTimer.Interval = new TimeSpan(0, 0, 1);
                }
            }
        }