LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to USB devices with libusb-win32, is it possible?

Has anyone had any success connecting to a USB device using the libusb-win32 package?  I tried to use VISA to communicate with my USB device but windows will not let it run since it already had a "signed" driver.  The driver I created to run with the libusb dll seems to be able to replace the windows driver and show up in device manager as a "libUSB-WIn32 Device" but I cant configure the dll calls to communicate with it.  It seems to use a complex system of structs and pointers that I haven't been able to replicate with LabVIEW.  Has anyone tried this before with any success?  Better yet does anyone have any sample code doing this?
The library is from  http://libusb-win32.sourceforge.net/
With the function documentation at http://libusb.sourceforge.net/doc/
Supposedly this should be able to connect to any USB device and allow communication.
Thanks for any help.
Regards,
Dave
0 Kudos
Message 1 of 29
(16,209 Views)
Dave,

I have never tried this personally. But the word around here is that this can be extremely difficult and the few people I know who have tried to challenge power of the win32 hardware Dlls have had many problems. And in the case of the USB, I have seen no success of yet. But this does not mean others in the community have not have more success, so hopefully someone else will find this thread and be able to help you!

Best of luck.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 2 of 29
(16,164 Views)

I just finished using libusb with LabVIEW 8.5.  The way to do it is to create a C language DLL that wraps around the libusb.dll.  This way you can abstract away any incompatible structs, handles, etc.  We started with 4 entry points: openUSB, readUSB, writeUSB and closeUSB.  The read and write DLL functions call the "bulk" I/O functions.  The open DLL function calls the "init", "find" and "open" functions.  The close DLL function calls the "release" and "reset" functions.  So far, everything is working great.

WB

0 Kudos
Message 3 of 29
(16,114 Views)
Funny timing, I just completed the same thing yesterday.  My initial plan was to write four functions, one function that does the init, find busses, find devices, claims the interface, sets the configuration and sets the alternate configuration.  Another function to open the device, one more for bulk read, and a final function to release and close the interface.  (Essentially Setup, Open, Read and Close which only pass a handle.)


However in the end I changed my plans to simply have an executable that finds the device, initializes, configures, reads and closes it.  My application is simple to just test that data is coming across the port.  While this does create extra overhead as opposed to simply leaving the port open it doesn't seem to have any ill effects and actually seems safer since if the cable comes out during the multi-day test it will not error out and just pick up where it left off on the next iteration after the cable is inserted.

Thanks for the reply, it would have killed me if you said it was simple to do as I spent hours trying to get it to work directly from LabVIEW without a glimmer of hope. 
-Dave

0 Kudos
Message 4 of 29
(16,103 Views)
Funny you should all bring this up right now.

I'm working on a nugget about USB with LabVIEW and VISA.  I can certainly echo the trials and tribulations of trying to get USB over VISA to work, but in the end I cracked it.

Will be coming soon.

Shane.
0 Kudos
Message 5 of 29
(16,096 Views)

I almost went the VISA route with using the VISA Wizard.  I was short of time and I had a DLL wrapper that was almost working with libusb so I elected the C language solution.  I would prefer to use VISA in the future so I would be most interested in your solution.  Was the VISA solution difficult?

WB

0 Kudos
Message 6 of 29
(16,090 Views)
"Was the VISA solution difficult?"

YES!  This is why I felt it necessary to write something on it.  I'm still editing the text and examples, but it should be coming up soon.

Cool thing is that it's platform-independent.  All the platform-dependent stuff is already handled within VISA.  OK, you need the device driver wizard on Windows, but under Linux (haven't tested Mac) you can access the devices directly without any fuss.

Shane
0 Kudos
Message 7 of 29
(16,087 Views)
Agreed, VISA is great and the driver development wizard is awesome in most cases. 
What about the instances where windows has a signed driver for your device and won't let the VISA driver take over?  I was faced with this where I could manually force windows to use the VISA driver but then was presented with "Error 10" device cannot start which Microsoft says is the generic error message when they don't know what else to say.  Faced with this is there any way to get it to "start" under Windows? 
I waded through tons of web pages and tech support and even contacted Belkin to try to modify the firmware (that was a worthless phone call) and in the end VISA couldn't take control of the device and "start" it.  With no other LV solutions I was forced to use evil text to make the wrapper.
0 Kudos
Message 8 of 29
(16,073 Views)
In case anyone hasn't found this USB tutorial on ni.com:

http://zone.ni.com/devzone/cda/tut/p/id/4478

Also, to understand the USB commands flying to/from a device, it looks like a USB sniffer or monitor might work really well (a search on Google turned up a handful of free ones).  I've never tried one, but I plan on it.  USB is such an important interface to understand and be able to work with (coding-wise).  I'm surprised NI hasn't come up with a much better tutorial on this by now.  The tutorial linked above is pretty old, and based on the comments at the bottom of that page it isn't as thorough as it maybe should be.

- Brad
0 Kudos
Message 9 of 29
(16,068 Views)
Not having VISA be able to start it means that you get no access whatsoever?

Then it'd be very difficult getting it working under VISA (impossible really).  I'm still getting to grips with the USB thing with VISA.  I don't see how isochronous transfer is possible in LV, or how we can do an interrupt transfer TO the device.....  Maybe these things are possible, I just don't know.

Shane.

@ K1200LT rider
The link you provide will be part of my nugget, but only the start.  After doing what the tutorial says, I was left with a sense of "What now?" for a few days.  I'll get my nugget up ASAP.


Message Edited by Intaris on 06-25-2008 10:06 AM
0 Kudos
Message 10 of 29
(16,065 Views)