如何从通过 USB 连接的扫描仪获取信号

How to get signals from a scanner connected over usb

我有一台柯达 i2600 扫描仪通过 SX Virtual Link 连接到网络,在该网络中的每台电脑上,它都模拟到扫描仪的 USB 连接。我可以像这样轻松找到模拟的 usbs pid 和 vid:

或者这个:

我尝试使用 LibUsbDotNet 检测信号,但在他们的示例中它不起作用。我试过这个例子:

public static UsbDevice MyUsbDevice;

#region SET YOUR USB Vendor and Product ID!

public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(int.Parse("040a", System.Globalization.NumberStyles.HexNumber), int.Parse("601d", System.Globalization.NumberStyles.HexNumber));


#endregion

public static void Main(string[] args)
{
    ErrorCode ec = ErrorCode.None;

    try
    {
        // Find and open the usb device.
        MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

        // If the device is open and ready
        if (MyUsbDevice == null) throw new Exception("Device Not Found.");

        // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
        // it exposes an IUsbDevice interface. If not (WinUSB) the 
        // 'wholeUsbDevice' variable will be null indicating this is 
        // an interface of a device; it does not require or support 
        // configuration and interface selection.
        IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
        if (!ReferenceEquals(wholeUsbDevice, null))
        {
            // This is a "whole" USB device. Before it can be used, 
            // the desired configuration and interface must be selected.

            // Select config #1
            wholeUsbDevice.SetConfiguration(1);

            // Claim interface #0.
            wholeUsbDevice.ClaimInterface(0);
        }

        // open read endpoint 1.
        UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);


        byte[] readBuffer = new byte[1024];
        while (ec == ErrorCode.None)
        {
            int bytesRead;

            // If the device hasn't sent data in the last 5 seconds,
            // a timeout error (ec = IoTimedOut) will occur. 
            ec = reader.Read(readBuffer, 5000, out bytesRead);

            if (bytesRead == 0) throw new Exception(string.Format("{0}:No more bytes!", ec));
            Console.WriteLine("{0} bytes read", bytesRead);

            // Write that output to the console.
            Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead));
        }

        Console.WriteLine("\r\nDone!\r\n");
    }
    catch (Exception ex)
    {
        Console.WriteLine();
        Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
    }
    finally
    {
        if (MyUsbDevice != null)
        {
            if (MyUsbDevice.IsOpen)
            {
                // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                // it exposes an IUsbDevice interface. If not (WinUSB) the 
                // 'wholeUsbDevice' variable will be null indicating this is 
                // an interface of a device; it does not require or support 
                // configuration and interface selection.
                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // Release interface #0.
                    wholeUsbDevice.ReleaseInterface(0);
                }

                MyUsbDevice.Close();
            }
            MyUsbDevice = null;

            // Free usb resources
            UsbDevice.Exit();

        }

        // Wait for user input..
        Console.ReadKey();
    }
}

在这个例子中,当我尝试打开 USB 设备时,结果是 null。所以我试图用这个例子来检测来自任何 USB 设备的任何信号:

public static IDeviceNotifier UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();

    private static void Main(string[] args)
    {
        // Hook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;

        // Exit on and key pressed.
        Console.Clear();            
        Console.WriteLine();
        Console.WriteLine("Waiting for system level device events..");
        Console.Write("[Press any key to exit]");

        while (!Console.KeyAvailable)
            Application.DoEvents();

        UsbDeviceNotifier.Enabled = false;  // Disable the device notifier

        // Unhook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify -= OnDeviceNotifyEvent;
    }

    private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
    {
        // A Device system-level event has occured

        Console.SetCursorPosition(0,Console.CursorTop);

        Console.WriteLine(e.ToString()); // Dump the event info to output.

        Console.WriteLine();
        Console.Write("[Press any key to exit]");
    }`

在这个例子中,我只能检测到 connectdisconnect 信号。所以我尝试使用 LibUsbDotNet 连接到 USB keyboard/mouse 端口,但也没有用。

It seems that i severely don't understand what needs to be done here.

接下来,我什至尝试使用来自 SO 的这个示例检查某个 USB 设备是否完全连接:USB Device Connected 即使这样也行不通。

总而言之,我需要这样做:

  1. 连接到扫描仪所连接的 USB 端口(并监听它通过该端口发送的信号)。
  2. 检测到来自扫描按钮的信号:
  3. 当检测到来自 2. 的信号时,我会向扫描仪发送一个信号,以使用我自己的配置使用 TWAIN 或 ISIS 库进行扫描。

我想你可以从供应商那里得到kodak perfect page SDK。 Pinvoke 供应商提供的调用。

检查 link 中的开发者工具部分 http://www.kodak.com/eknec/PageQuerier.jhtml?pq-path=2714&pq-locale=en_US&_requestid=3863