Accessing a USB Bill Acceptor via USB in .NET

Hello,

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.
http://www.validationtech.com/sellsheet/matrix%20sell%20150.pdf

Thanks to anyone that can help!

-Sean
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;

        #endregion

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

            MyUsbFinder = new UsbDeviceFinder(3301, 1);
            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)
                // 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
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(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;
                do
                {
                    // 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)
                    {
                        usbReadTransfer.Dispose();
                        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);

                    usbWriteTransfer.Dispose();
                    usbReadTransfer.Dispose();

                    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));
                    testCount++;
                } while (testCount < 5);
                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();
            }
        }
    }
}

Open in new window

andplusdesignAsked:
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.

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

however, there are some important points mentioned as well. Have you followed those?

http://libusbdotnet.sourceforge.net/V2/html/e61bb81e-108b-4f84-a77d-8ccdecebfa31.htm
http://libusbdotnet.sourceforge.net/V2/html/8564be8a-3154-4b2e-8017-5013ca8244ee.htm
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.
grayeCommented:
Here is a link to a C# port of the Microsoft USBView utility.  You might find the source code useful...

http://www.emmet-gray.com/Programs/Developer%20Tools/USBView.zip 

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
crBynumCommented:
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 jmbynum@sbcglobal.net 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.