1

Topic: Have issues trying to get 16-bit joystick inputs consistently

Hello. As the title says, I'm having trouble trying to run a 16-bit joystick/hardware. Sometimes, it works when I run the code. Sometimes it doesn't. It's inconsistent and I need help.

I have no troubles with 8-bit. Just with 16-bit joystick I'm having troubles with.

Here's the code:

static void Main()
{
    var list = DeviceList.Local;
    
    var joystick = list.GetHidDeviceOrNull(productID: 12345);

    if (joystick != null)
    {
        using (var stream = joystick.Open())
        {
            var inputReportBuffer = new byte[joystick.GetMaxInputReportLength()];
            while (true)
            {
                try
                {
                    int length = stream.Read(inputReportBuffer, 0, inputReportBuffer.Length);
                    Console.Write($"Worked!\n");
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    Console.Write($"Crashed!\n");
                    Console.WriteLine($"Exception: {ex.Message}\n{ex.StackTrace}");
                }

            }
        }
    }
    else
    {
        Console.WriteLine("Joystick not found.");
    }
}

Please help me. I really appreciate any kind of help.