Error trying to use class / method of a library.

0

I'm trying to connect a WPF with external hardware through the usb. I installed NuGet HIDSharp and declared USB Devices as below:

HidDevice _device;
HidStream _deviceStream;
IEnumerable<HidDevice> _deviceList;

That's within public partial class MainWindow : Window . I created the ConnectToUsb method and inside it DeviceList use coming from the HidSharp library that was declared as using HidSharp;

But VS is reporting an error in DeviceList saying that it does not exist in that context, even though I have declared the library and even the method being inside the main class. Has anyone gone through this and would have a possible solution?

private async Task<bool> ConnectToUsb()
        {

            await Task.Delay(1000);
            try
            {
                //manda conectar no dispositivo
                _deviceList = DeviceList.Local.GetHidDevices();
                _device = _deviceList.FirstOrDefault(dev => dev.ProductID == _Pid && dev.VendorID == _Vid && dev.DevicePath.Contains("col01"));
                //inicia o background worker caso encontre
                if (_device != null)
                {
                    //Conecta na placa encontrada
                    _device.Open();
                    if (_device.TryOpen(out _deviceStream))
                    {
                        // TODO Mostrar a capacidade do HID
                        WriteLog($"Placa {cmbBoard.SelectedItem.ToString()} encontrada!", Brushes.Gray);

                        WriteLog("Comunicação estabelecida com sucesso", Brushes.Gray);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    //Não encontrou nenhum dispositivo
                    // WriteMessage("Erro na Conexão USB!", Brushes.Red);
                    WriteLog("Não foi possível encontrar nenhuma Placa!", Brushes.Red);
                    return false;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("Erro ao tentar conectar ao dispositivo! " + ex.ToString());
                WriteLog("Erro ao tentar conectar ao dispositivo: " + ex.ToString(), Brushes.Gray);
                return false;
            }

        }
    
asked by anonymous 20.03.2018 / 22:26

2 answers

3

This class is not available in version 1.5.0. Which, second to this previous question, is the version you have referenced .

In the assembly section, in the class documentation you can check

  

Namespace : HidSharp
Assembly : HidSharp (in HidSharp.dll) Version: 2.0.0-alpha

You can install this version, but keep in mind that it is an alpha version. It is at your own risk.

To install it just use the

PM> Install-Package HidSharp -Version 2.0.0-alpha
    
20.03.2018 / 22:54
1

By error message:

  

The name 'DeviceList' does not exist in the current context.

I think maybe the problem is in your class, where you call:

 _deviceList = DeviceList.Local.GetHidDevices();

If you have more than one script / document that is using HidDevice, then perhaps one of them you have forgotten to declare using HidSharp; , check all documents that will use the class.

    
20.03.2018 / 23:07