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)

Most upvoted comments

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:

@NikolayUvarov https://github.com/NikolayUvarov V3 has been released. Are you still having the same issue?

Please see this article to help diagnose the issue

https://github.com/MelbourneDeveloper/Device.Net/wiki/Debugging,-Logging,-and-Tracing

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MelbourneDeveloper/Device.Net/issues/71?email_source=notifications&email_token=AB432NNTAII7PVP5BPSK363QFOEZPA5CNFSM4H4SWZW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4VGLNQ#issuecomment-522872246, or mute the thread https://github.com/notifications/unsubscribe-auth/AB432NLUO4D72K7ZQAYJ2W3QFOEZPANCNFSM4H4SWZWQ .

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:

@NikolayUvarov https://github.com/NikolayUvarov V3 has been released. Are you still having the same issue?

Please see this article to help diagnose the issue

https://github.com/MelbourneDeveloper/Device.Net/wiki/Debugging,-Logging,-and-Tracing

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MelbourneDeveloper/Device.Net/issues/71?email_source=notifications&email_token=AB432NNTAII7PVP5BPSK363QFOEZPA5CNFSM4H4SWZW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4VGLNQ#issuecomment-522872246, or mute the thread https://github.com/notifications/unsubscribe-auth/AB432NLUO4D72K7ZQAYJ2W3QFOEZPANCNFSM4H4SWZWQ .

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:

@NikolayUvarov https://github.com/NikolayUvarov , sorry about the short reply last time. I want to help you get this working. I am just very busy trying to get the changes done for 3.0 https://github.com/MelbourneDeveloper/Device.Net/projects/8 . Here is what I need you to do so I can diagnose the problem:

  • Use Windows 10
  • Clone this repo
  • In your project, drop all the NuGet package references for this repo
  • Add the projects from this repo that you need one by one to your solution (instead of the NuGet packages)
  • Turn on break on all exceptions. I have written a guide just for you here https://christianfindlay.com/2019/07/14/visual-studio-break-on-all-exceptions/ .
  • Run the app
  • Take screenshots, and copy the ToString() of any Exceptions you see

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MelbourneDeveloper/Device.Net/issues/71?email_source=notifications&email_token=AB432NLN26RNWEQX2ZX7RSLP7J26HA5CNFSM4H4SWZW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ34BGY#issuecomment-511164571, or mute the thread https://github.com/notifications/unsubscribe-auth/AB432NPMB2LZDDAKZC3IJVDP7J26HANCNFSM4H4SWZWQ .