0
I am trying to connect a WPF to an external hardware via usb. I installed the Hidsharp Nuget and declared the USB Devices as below:
HidDevice _device;
HidStream _deviceStream;
IEnumerable<HidDevice> _deviceList;
That within the public partial class MainWindow : Window
.
I created the method ConnectToUsb
and within it use DeviceList
from the library Hidsharp which has been declared as follows using HidSharp;
But VS is reporting me 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 within the main class. Someone has already been 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;
}
}
What is exactly the error that is presented?
– Jéf Bueno
the name 'Devicelist' does not exist in the Current context.
– Eduardo Cardoso
And this
DeviceList
is a library class/namespace?– Jéf Bueno
Yes, class Hidsharp.DeviceList. Provides a list of all available.
– Eduardo Cardoso
What version of the package you are using?
– Jéf Bueno
I’m using version 2.0.0-alpha.
– Eduardo Cardoso
Installed by Nuget? If so, you can post the contents of the file Packages.config?
– Jéf Bueno