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

时间:2015-03-09 11:20:55

标签: c# libusbdotnet

我有一台KODAK i2600扫描仪通过SX Virtual Link连接到网络,该网络中的每台PC都模拟与扫描仪的usb连接。我可以很容易地找到模拟的usbs pid和vid: device manager detects the scanner as if it is connected via usb

或者:registry editor also shows info as it's connected over usb

我试图用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键盘/鼠标端口,这也没有用。

  

似乎我severely并不了解需要做什么   这里。

接下来,我尝试通过SO来检查某个USB设备是否与此示例完全连接:USB Device Connected 即使这样也没有用。

总结一下,我需要这样做:

  1. 连接到连接扫描仪的USB端口(并侦听通过该端口发送的信号)。
  2. 检测来自扫描按钮的信号:button to scan a paper
  3. 当检测到来自2.的信号时,我向扫描仪发送信号,使用我自己的配置用TWAIN或ISIS lib进行扫描。

1 个答案:

答案 0 :(得分:0)

我认为您可以从供应商那里获得柯达完美页面SDK 。 锁定供应商提供的电话。

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