Exemplo n.º 1
0
        private void FindMyDevice()
        {
            try
            {
                const uint pipeTimeout = 20;
                if (!(_deviceReady))
                {
                    // Convert the device interface GUID String to a GUID object:
                    var winUsbDemoGuid = new Guid(DeviceInterfaceGuid);

                    // Fill an array with the device path names of all attached devices with matching GUIDs.
                    var deviceFound = _myDeviceManagement.FindDeviceListeFromGuid(winUsbDemoGuid, ref deviceListeFound);

                    if (deviceFound)
                    {
                        foreach (Device _device in deviceListeFound)
                        {
                            _device._deviceHandle = _myWinUsbCommunications.GetDeviceHandle(_device._devicePathName);

                            if (!_device._deviceHandle.IsInvalid)
                            {
                                _device._deviceReady = true;

                                _myWinUsbCommunications.InitializeDevice(_device._deviceHandle, ref _device._winUsbHandle, ref _device._myDeviceInfo, pipeTimeout);

                                DisplayDeviceSpeed(_device);
                            }
                            else
                            {
                                // There was a problem in retrieving the information.
                                _device._deviceReady = false;
                                _myWinUsbCommunications.CloseDeviceHandle(_device._deviceHandle, _device._winUsbHandle);
                            }
                        }
                    }
                }
                else
                {
                    DisplayDeviceSpeed(null);
                }

                // Display device information.
                FindDeviceUsingWmi();
                MatchFoundDeviceUsingVidPid();
            }
            catch (Exception ex)
            {
                DisplayException(Name, ex);
                throw;
            }
        }
Exemplo n.º 2
0
        private void FindMyDevice()
        {
            try
            {
                const uint pipeTimeout = 20;

                if (!(_deviceReady))
                {
                    // Convert the device interface GUID String to a GUID object:

                    var winUsbDemoGuid = new Guid(DeviceInterfaceGuid);

                    // Fill an array with the device path names of all attached devices with matching GUIDs.

                    //var deviceFound = _myDeviceManagement.FindDeviceFromGuid(winUsbDemoGuid, ref devicePathName);//Modif VB

                    var deviceFound = _myDeviceManagement.FindDeviceListeFromGuid(winUsbDemoGuid, ref deviceListeFound);

                    if (deviceFound)
                    {
                        foreach (Device _device in deviceListeFound)//MODIF VB le foreach n'existait pas avant
                        {
                            //_deviceHandle = _myWinUsbCommunications.GetDeviceHandle(devicePathName);
                            _device._deviceHandle = _myWinUsbCommunications.GetDeviceHandle(_device._devicePathName);

                            if (!_device._deviceHandle.IsInvalid)
                            {
                                _device._deviceReady = true;

                                _myWinUsbCommunications.InitializeDevice(_device._deviceHandle, ref _device._winUsbHandle, ref _device._myDeviceInfo, pipeTimeout);

                                DisplayDeviceSpeed(_device);
                            }
                            else
                            {
                                // There was a problem in retrieving the information.

                                _device._deviceReady = false;
                                _myWinUsbCommunications.CloseDeviceHandle(_device._deviceHandle, _device._winUsbHandle);
                                //LstResults.Items.Add("Device not found.");
                                //MyMarshalToForm(FormActions.AddItemToListBox.ToString(), "Device not found.");
                            }
                        }
                    }
                    else
                    {
                        //CmdSendandReceiveViaBulkTransfers.Enabled = true;
                        //CmdSendAndReceiveViaInterruptTransfers.Enabled = true;
                    }
                }
                else
                {
                    //LstResults.Items.Add("The device has been detected.");
                    Console.WriteLine("The device has been detected.");
                    DisplayDeviceSpeed(null);
                }

                // Display device information.

                FindDeviceUsingWmi();
                MatchFoundDeviceUsingVidPid();
                //ScrollToBottomOfListBox();
                //MyMarshalToForm(FormActions.ScrollToBottomOfListBox.ToString(), "");
            }
            catch (Exception ex)
            {
                DisplayException(Name, ex);
                throw;
            }
        }