I need to interface to a USB device from VB.net, where I both read and write to the device.

Are there any programing differences between the different USB interfaces, i.e 1,2 and 3 that I should be aware ?

Does it matter if say a USB 3 device is plugged into a USB2 port ?

Thanks for your help

Dani AI

Generated

Short answer: the USB revision (1.x / 2.0 / 3.x) mainly affects physical speed, signaling and available bus power. The API an application uses is determined by the device’s class and which driver is installed (HID, CDC/Virtual‑COM, Mass Storage, or a vendor/WinUSB driver), not by whether the hardware speaks SuperSpeed. A USB‑3 device plugged into a USB‑2 port will normally enumerate and run at the lower speed (and may be limited by the lower power budget), so the code path is the same — only throughput and power change. (learn.microsoft.com)

Practical VB.NET options to consider (pick based on the device class exposed by the hardware): if the device appears as a serial COM port use System.IO.Ports.SerialPort; if it’s an HID device use the Windows HID APIs or a managed wrapper (for example HidLibrary or HidSharp); if it’s a generic bulk/interrupt device use WinUSB (winusb.dll) via P/Invoke or a .NET wrapper, or libusb/LibUsbDotNet for cross‑platform or non‑Windows drivers. These are the usual, supported routes that avoid writing kernel drivers in VB. (learn.microsoft.com)

Troubleshooting and deployment tips (ties to and observations): front panel ports and some laptop ports can be flaky or underpowered — try a rear port or a powered hub for reliability. Use USBView or Device Manager to inspect VID/PID, reported speed and requested power before writing code; that reveals whether the device is HID/CDC/WinUSB and how many endpoints it exposes. For shipping to users, prefer either a standard class driver or provide a properly signed INF/driver package; WinUSB can be automatically used if the device exposes the compatible ID. (learn.microsoft.com)

Small VB.NET example for a virtual COM device (synchronous write/read):

Dim sp As New IO.Ports.SerialPort("COM3", 115200)
Try
    sp.Open()
    Dim payload() As Byte = {&H01, &H02, &H03}
    sp.Write(payload, 0, payload.Length)
    Dim buf(1023) As Byte
    Dim n = sp.Read(buf, 0, buf.Length)
Finally
    If sp IsNot Nothing AndAlso sp.IsOpen Then sp.Close()
End Try

Start by running USBView to confirm class and endpoints, then pick the matching approach above (SerialPort, HID wrapper, WinUSB/libusb) and test on both USB‑2 and USB‑3 ports to catch power/throughput issues early.

Recommended Answers

All 6 Replies

That's a fair start but without knowing the device well, where to go next?

As to USB 1,2,3 as long as the device driver works, all good. About the only trouble could be if you happen to get a customer with some USB 1.0 on Windows 95 to ME machine. But you are likely to not write for those old platforms.

And to state it plainly I've yet to find anyone write a device driver in VB.

Well spotted. I would love to share it, but project is now only just about to happen.

To make myself clear - I'm not writing device driver, just using the one supplied to talk to the device. I am trying to preempt any possible problems there might be between the different versions of USB.

My guess is the device will probably be USB 3, and will only be running on later versions of Windows, so older ones won't be a problem.

Then one thing. I find trouble in front USB ports on many cases. That's not an error for your code to correct or to fix your client's PCs unless that's your choice. I'm sure that somewhere you will find some USB issue someday. For example I have this older XP all patched up laptop USB 2.0 and once in a while a BSOD due to some driver error. There is no hope of fixing that but on a newer laptop, never saw it happen.

A newer coder might think it was theirs to fix.

Then we have the USB device driver install headaches. While I've written instructions on the device I used in one system I support it never fails that folk will come back with "it doesn't work." Their laptop is shipped in and we run through the device install and it's all good. Makes you wonder at times but maybe not. A lot of folk don't want to deal with Windows, they just want.

commented: helpful +15

I've noticed two things with USB ports

1) if you install a printer on one port, then move it to another port, it will reinstall, so the printer is listed twice in the printer dialog box.

2) on my laptop I'll plus an external hard drive in and it won't always work on some ports. Next time it will work fine on that port.

Item 1 sounds like the usual. Item 2 for HDDs is again sadly normal as not all ports have the same power available. For that reason I have a few USB Y cables to tap a second port for more power.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.