Results 1 to 12 of 12

Thread: Reading from a USB port

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Reading from a USB port

    How do I read data from a USB port. If I plug in the USB adapter, say from the mouse adapter can my VB program read the data from that USB port

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Reading from a USB port

    That depends on what you have plugged into the usb port and what kind of interface/drivers it has.
    A flash drive yes, a usb serial adapter yes some random USB device who knows, maybe, maybe not.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Re: Reading from a USB port

    Incorrect reply on my part see next post
    Last edited by On Error Try Again; Sep 25th, 2016 at 02:30 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Re: Reading from a USB port

    Well I did mention the usb adapter from my mouse. I believe there is some app or the OS itself that reads from that plugged in adapter else how would it control the mouse movements. So, if it can read it then why not my VB app or if not VB then maybe a C or Assembly written program

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Reading from a USB port

    USB adapter from your mouse? I have no idea what you mean by that, perhaps a wireless adapter that came with your mouse? At any rate a mouse is handled by the mouse driver and VB sees it via the mouse events which it gets from the OS. VB does not care if the mouse is USB, wired,wireless, serial or PS/2 it is all handled by the mouse driver.

    No you can not talk directly to a USB port from VB6. You talk to the driver for whatever device you are using.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Re: Reading from a USB port

    This is not about how VB sees the mouse through the mouse events. The mouse's USB wireless adapter is just an example of what I am referring to. I'am asking how can I read the data from that adapter (for example only) regardless of what's involved. In other words if a driver can read the signals from the adapter then why can I not do the same thing even if it means not using VB but maybe a C or Assembly program. After all, a driver is nothing more than a program, right. I guess you might say I want to write my own driver if that helps explain it better.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Reading from a USB port

    USB "ports" are just a variety of I/O expansion slot, thus the "Bus" in "Universal Serial Bus."

    Thinking they are anything like a simple COM1: or LPT3: "port" is incorrect. They are not "ports" at the same level of abstraction at all.

    Your question is analogous to saying "I want my VB6 program to talk to a PCI bus slot." Applications do not directly use such "slots" but only cards plugged into them, and even then only through the mediation of several layers of software.

    While there are some low-level drivers in Windows for talking to several classes of generic USB devices a mouse is not one of them. Mouse devices, like keyboards and others are owned by the OS and you can only see them as a mouse or a keyboard.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Re: Reading from a USB port

    I don't care about the mouse. I don't care about the keyboard. I wish you two would quit elaborating about the damn mouse, it was only an example, a very abstract example for that matter. I was just using it as a kind of a metaphor. I'm asking how can I communicate with the adapter that you plug into a USB slot (since they are not ports as you say) in any language. Many years ago I had a computer software game that came with a remote control and a USB adapter. You put batteries into the remote control and the adapter into any USB slot. The user then used the remote control to manipulate the game but that was ages ago and I no longer have any of that left so I know it can be done. I simply want to create basically the same thing but instead of a game some other software application
    Last edited by On Error Try Again; Sep 26th, 2016 at 02:24 AM.

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Reading from a USB port

    The point was that there is no generic way to deal with any given USB device, it's completely different from a COM or LPT port.
    You always communicate via a driver.

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Reading from a USB port

    There are libraries that allow you to access the USB buses in a raw manner, but as dilettante has pointed out it is not a simple thing to do. There is a complicated hierarchy and protocol to understand before you can attempt to interpret the data.
    You can read up on USB technical aspects for some groundwork.
    And perhaps you would like to download and run USBPcap to start to get a feel for it.
    Later versions of Wireshark support using USBPcap to capture and display USB packets as well, so you might want to download and run that to inspect the packet streams to inspect the packets for whatever device you're interested in.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Reading from a USB port

    If we knew what the real problem was instead of just the blind alley "solution" being pursued there might be a fairly simple answer.

    For example HID game controllers are supported by Windows and you can get at those from a program via related Win32 APIs, DirectX APIs, etc.

  12. #12
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Reading from a USB port

    Yeah - the problem is @OETA keeps using something specific as an example - but somehow wants a generic answer...
    The specific answer is no. Low level communication is done via a driver (which could possibly be written could be written VB6, but most likely C/C++) These drivers have access to low level protected OS APIs needed to communicate directly with hardware. Normal programs don't have access to these APIs.

    Even if you did have access to these API(s) let's say you're writing a driver, you then need to know how the specific hardware works. For something like your wireless mouse adapter, you wouldn't have a clue how to interpret or access it - because it's proprietary (and you have no clue how to reverse engineer it), and only the oem would have those specifics.

    passel posted a great idea on how to view USB packets, to give you an idea of just how the data get's shuttled around on the same bus. Feel free to try and reverse the protocol that way

    If you were going to make something more generic yourself - you could use a Serial to USB adapter. Incidentally this is how a lot of hardware is developed, using a generic serial protocol, and piggy backing on the Serial to USB Chip's driver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width