Device.Net: Code, which works in Win7 gets exception in Win10 (standart app)
I have simple test form with a textfield and button, visual studio community 2017. This code works perfect in windows7, but the same code in windows10 device is no. I am getting error in line line await myHidDevice.WriteAsync(buffer); showing System.NullReverenceException in DeviceTerminal.Form1.<InitializeMyHid>d__4.MoveNext() This code is copy from the example.
`
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Device.Net;
using Hid;
using Hid.Net;
using Hid.Net.Windows;
namespace DeviceTerminal
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static IDevice myHidDevice;
private static async void InitializeMyHid()
{
WindowsHidDeviceFactory.Register();
//Define the types of devices to search for. This particular device can be connected to via USB, or Hid
var deviceDefinitions = new List<FilterDeviceDefinition>
{
new FilterDeviceDefinition{ DeviceType= DeviceType.Hid, VendorId= 0x0418, ProductId=0xf212 },
};
//Get the first available device and connect to it
var devices = await DeviceManager.Current.GetDevicesAsync(deviceDefinitions);
myHidDevice = devices.FirstOrDefault();
await myHidDevice.InitializeAsync();
//Create a buffer with 3 bytes (initialize)
var buffer = new byte[64];
buffer[0] = Convert.ToByte('R');
buffer[1] = Convert.ToByte('\n');
buffer[2] = 0;
//Write the data to the device
await myHidDevice.WriteAsync(buffer);
//Read the response
var readBuffer = await myHidDevice.ReadAsync();
string readText = Encoding.UTF8.GetString(readBuffer, 0, readBuffer.Length);
Program.form1.textBox1_log.Invoke(new Action(() => Program.form1.textBox1_log.AppendText("Got string: " + readText)));
}
private async void button1_Click_1Async(object sender, EventArgs e)
{
InitializeMyHid();
}
}
}
`
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 23 (12 by maintainers)
Version 3.0.0 works fine in Win10! Thanks! The issue when I could see my device in win7 and can’t in win10 is now resolved.
вт, 20 авг. 2019 г. в 09:33, Nikolay Uvarov nikolay.uvarov@gmail.com:
I did not knew that, thanks! I will report if any and if not also. Thanks again!
вт, 20 авг. 2019 г. в 09:24, Christian Findlay notifications@github.com:
Sry It was chopped off. I will redo the procedure.
I was analyzing yesterday and APICalls.CreateFile returned a SafeFileHandle just fine, with a valid Handle. The error code 87 was returned by HidD_GetManufacturerString.
The device is an HID-compliant mouse, and It probably cannot be queried in Windows 10 for security reasons. With HIDSharp, TryOpen also doesn’t work, as this case https://forum.zer7.com/topic/10122/ . I don’t know if there is a workaround.
Thank you very much! Curriently I am abroad, will be able to check all stuff this weekend (or maximum beginning of the next week).
вс, 14 июл. 2019 г. в 03:59, Christian Findlay notifications@github.com: