Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Hidlibrary仅连续报告零_C# - Fatal编程技术网

C# Hidlibrary仅连续报告零

C# Hidlibrary仅连续报告零,c#,C#,设备不停地报告00,00,00,00,我试过的设备没有一个报告正确的字节,只是零或静默。我能做什么?我正在尝试捕捉鼠标非标准按钮点击,USBlyzer说它发送80 00,但这里只有零 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; us

设备不停地报告00,00,00,00,我试过的设备没有一个报告正确的字节,只是零或静默。我能做什么?我正在尝试捕捉鼠标非标准按钮点击,USBlyzer说它发送80 00,但这里只有零

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HidLibrary;

namespace MouseHandler
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /*private const int VendorId = 0x09DA;
        private const int ProductId = 0x000A;
        private const int VendorId = 0x046D;
        private const int ProductId = 0xC52B;*/
        private const int VendorId = 0x0D8C;
        private const int ProductId = 0x013C;

        private static HidDevice device;
        bool paused = false;

        private void Form1_Load(object sender, EventArgs e)
        {
            device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault();
            if (device != null)
            {
                device.OpenDevice();
                device.MonitorDeviceEvents = true;
                device.ReadReport(rreport);
            }
        }
        private void rreport(HidReport report)
        {
            if (!paused)
            {
                write(string.Join(", ", report.Data.Select(b => b.ToString("X2"))));
                device.ReadReport(rreport);
            }
        }
        void write(string text)
        {
            if (ControlInvokeRequired(textBox1, () => write(text))) return;
            textBox1.AppendText(text + Environment.NewLine);
        }
        public bool ControlInvokeRequired(Control c, Action a)
        {
            if (c.InvokeRequired) c.Invoke(new MethodInvoker(delegate { a(); }));
            else return false;

            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            paused = !paused;
            device.ReadReport(rreport);
        }
    }
}

你有没有用调试器查看报表数据结构?这个数组真的包含零吗?如果您确实收到零,则可能是设备型号的问题。由于可能的设备配置数量巨大,因此对该库的支持非常有限。也许你需要编写自己的低级过滤器驱动程序。@VitaliyK是的,它只是零,我想这还是我的错,因为我试过的所有设备都不工作。如果您熟悉hidlibrary,您认为我的代码中的任何内容都可能导致此问题吗?之前在我的一个项目中,我们在设备和hidlibrary方面也有相同的问题-它只是在很多情况下不起作用。因此,我们创建了一个低级驱动程序来获取报告。您还可以检查设备上的不同事件,如插入或删除等,如果它们正常工作。最后,您可以从GitHub下载源代码并手动调试库。从您的代码部分来看,一切看起来都简单而美好。