0

我正在尝试学习如何在 C# 的 LibUsbDotNet 库中编程 USB 交互。尝试简单的轮询读取时,我的设备被识别但无法打开。我使用了两种设备,一种是 Vernier Force Probe(我正在尝试实际使用的设备),另一种是恰好是我 PC 上的鼠标的测试设备。鼠标可以正常打开并继续读取,但在使用 Force Probe 时,UsbDevice.Open() 方法会返回错误。这是代码:

using System;
using System.Text;
using LibUsbDotNet;
using LibUsbDotNet.LibUsb;
using LibUsbDotNet.Main;

namespace Examples
{
    internal class ReadPolling
    {
        public static IUsbDevice MyUsbDevice;

        public static void Main(string[] args)
        {
            Error ec = Error.Success;

            using (UsbContext context = new UsbContext())
            {
                try
                {
                    MyUsbDevice = context.Find(device => (device.ProductId == 3) && 
                        (device.VendorId == 0x08F7));

                    if (MyUsbDevice == null) throw new Exception("Device Not Found.");
                    
                    MyUsbDevice.Open();
                    //this is the line that throws the exception "Input/Output Error"

任何线索我的代码有什么问题或我的一个设备的格式有问题导致它抛出这个异常?

4

0 回答 0