Accessing a USB Bill Acceptor via USB in .NET


I am using the attached example code for LibUSBDotNet, and I'm not able to access any USB device at all, regardless of the values I put in to the usbfinder method.

Needless to say, no matter how many times I run this, debug this, or trace things, I am receiving "Device Not Found." on the console.

I am *not* married to LibUsbDotNet, I simply need to speak to this USB device.

The USB device is a Matrix VTI bill acceptor, and ships with an example program and clear explanations as to how to interface with it - but I can't send or receive any of the data to it if I can't access the device.

Thanks to anyone that can help!

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using LibUsbDotNet;
using LibUsbDotNet.Main;
using LibUsbDotNet.LudnMonoLibUsb;

namespace Examples
    internal class ReadWriteAsync
        public static UsbDevice MyUsbDevice;

        #region "SET YOUR USB Vendor and Product ID!"

        public static UsbDeviceFinder MyUsbFinder;


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

            MyUsbFinder = new UsbDeviceFinder(3301, 1);
                // 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)
                // it will have an IUsbDevice interface. If not (WinUSB) the 
                // variable will be null indicating this is an interface of a 
                // device.
                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

                    // Claim interface #0.

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

                // open write endpoint 1.
                UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);

                // the write test data.
                string testWriteString = "ABCDEFGH";

                ErrorCode ecWrite;
                ErrorCode ecRead;
                int transferredOut;
                int transferredIn;
                UsbTransfer usbWriteTransfer;
                UsbTransfer usbReadTransfer;
                byte[] bytesToSend = Encoding.Default.GetBytes(testWriteString);
                byte[] readBuffer = new byte[1024];
                int testCount = 0;
                    // Create and submit transfer
                    ecRead = reader.SubmitAsyncTransfer(readBuffer, 0, readBuffer.Length, 100, out usbReadTransfer);
                    if (ecRead != ErrorCode.None) throw new Exception("Submit Async Read Failed.");

                    ecWrite = writer.SubmitAsyncTransfer(bytesToSend, 0, bytesToSend.Length, 100, out usbWriteTransfer);
                    if (ecWrite != ErrorCode.None)
                        throw new Exception("Submit Async Write Failed.");

                    WaitHandle.WaitAll(new WaitHandle[] { usbWriteTransfer.AsyncWaitHandle, usbReadTransfer.AsyncWaitHandle },200,false);
                    if (!usbWriteTransfer.IsCompleted) usbWriteTransfer.Cancel();
                    if (!usbReadTransfer.IsCompleted) usbReadTransfer.Cancel();

                    ecWrite = usbWriteTransfer.Wait(out transferredOut);
                    ecRead = usbReadTransfer.Wait(out transferredIn);


                    Console.WriteLine("Read  :{0} ErrorCode:{1}", transferredIn, ecRead);
                    Console.WriteLine("Write :{0} ErrorCode:{1}", transferredOut, ecWrite);
                    Console.WriteLine("Data  :" + Encoding.Default.GetString(readBuffer, 0, transferredIn));
                } while (testCount < 5);
            catch (Exception ex)
                Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
                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.

                    MyUsbDevice = null;

                    // Free usb resources

                // Wait for user input..

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I found of a couple of examples on the links below -

however, there are some important points mentioned as well. Have you followed those?
Arno KosterCommented:
I assume you have installed the supplied device driver and the thing is visible in windows hardware device manager ?
andplusdesignAuthor Commented:
@akoster - yes, your assumption is correct.  

@SameerJaqdale, those examples are the same code I pasted in the question.  And in terms of the important points, yes, I followed those (i.e. verified resources).

Thanks for the help, I hope someone has a working example here...
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Arno KosterCommented:
the pdf file indicates it also can talk over RS232, have you tried communicating with it using a com port ?
also : which operating system do you use ?
andplusdesignAuthor Commented:
Hi Akoster, no I haven't tried communicating over a COM port - I understand that sometimes USB is just a virtual COM port?  I am on Windows 7.
Here is a link to a C# port of the Microsoft USBView utility.  You might find the source code useful... 

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hello andplusdesign, Iam really interested in your solution I have a matrix usb bill acceptor I can do nothing with. If you could contact me at I would be very grateful
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.