/// <summary>
        /// When an entry is selected from the list of devices, we will connect to the device.
        /// If a device was previously connected, disconnect from that device first before connecting to the new device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void ConnectDevices_SelectChanged(Object sender, SelectionChangedEventArgs eventArgs)
        {
            var             deviceList = (ListBox)sender;
            var             selection  = deviceList.SelectedItems;
            DeviceListEntry entry      = null;

            if (selection.Count > 0)
            {
                var obj = selection[0];
                entry = (DeviceListEntry)obj;
            }

            var currentlySelectedId = (DeviceList.Current.IsDeviceConnected
                ? DeviceList.Current.CurrentDeviceEntry.Id
                : null);
            var newlySelectedId = (entry != null) ? entry.Id : null;

            // If we were already connected to another device, disconnect from that device.
            if (currentlySelectedId != null)
            {
                CloseDevice();
            }

            if (newlySelectedId != null)
            {
                OpenDevice(newlySelectedId);
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves the previously opened device's id so that it can be used to reopen a device.
        /// Sets the current device and it's device entry.
        /// </summary>
        public void SetCurrentDevice(String id, HidDevice device)
        {
            if (IsDeviceConnected)
            {
                previousDeviceId = currentDeviceEntry.Id;
            }

            currentDevice = device;

            currentDeviceEntry = FindDevice(id);
        }
Exemple #3
0
        public void AddDeviceToList(DeviceInformation deviceInformation)
        {
            // search the device list for a device with a matching interface ID
            var match = FindDevice(deviceInformation.Id);

            // Add the device if it's new
            if (match == null)
            {
                // Create a new element for this device interface, and queue up the query of its
                // device information
                match = new DeviceListEntry(deviceInformation);

                // Add the new element to the end of the list of devices
                listOfDevices.Add(match);
            }
        }