I have a program that will periodically try to talk to ~40 devices connected via multiple USB hubs. To my knowledge, there is no way to differentiate these devices based on data stored in the unit. The devices attached will constantly be changing over time as well. What I was wondering is how to target a specific usb hub's port. So for example, I have a device connected in hub 2 port 4 and a device connected to hub 4 port 1. I want the software to scan each and every port on each and every hub so that I can catch that these two ports have something attached while none of the others do. Is there a way to target and check every port statically? More so maybe I'm just asking if there's a way I can see USB addresses on a windows PC and talk to that.
Related
I need to detect when the Windows system is connected to/disconnected from network (LAN or WLAN) in C++ and without using WMI.
I have found a way to do this for wireless networks. (I have answered my own question here after finding a way), but this does not work (obviously) when I connect/disconnect a LAN cable.
How can I detect a change in network connection when user has connected a LAN cable to his Windows system? Is there a general way (instead of having separate code for WLAN and LAN) to find this?
Note: The network may or may not be connected to the internet.
I have searched a lot and was unable to find the Answer for the Query.
I wanted to find out how many USB ports are available in PC, i.e like for serial port we have "COM1" and "COM2". My PC (windows7) contains 8 USB ports I need to find the list of ports along with whether they are used or not used.
I have tried using WMI query with no result as it gives details of only connected devices and USB hubs only.
With Win DDK it will display all the ports available with each HUB but interestingly that is not the same as I see from outside. Win DDK will give how many ports are addressable from each hub not the exact no of ports visible from outside. Any C or C++ code would be of great help.
The ideal result would be something like this:
USB 1 USED
USB 2 Not USed
USB 3 USED
USB 4 Not Used
.....
You cannot determine this. The simple reason is that you want to make a distinction between hubs inside your computer and hubs outside. It's likely that at least some of those 8 USB ports on your PC are linked to a hub soldered on your motherboard.
Also, it's not uncommon for USB to be used as an internal-only connection. E.g. many SD card readers are connected to an internal USB hub. To software, this looks like a USB port, but it's of course not visible on the outside of your PC.
Once my embedded device is connected to USB port of my PC, it should trigger an exe as an event. How can I achieve this??
Should I create a service to keep monitoring the USB connector bus or is there any default API's available in Windows to achieve this??
thanks.
A simple exe which is started on connect is not possible. But you can write a service or user mode application which listens for device arrival events. WM_DEVICECHANGE is sent to all (registered) applications with a device interface guid which represents which device is plugged in. You can then use this id with the setupapi to see if its your device.
On receiving that event, you can then start your executable.
Depending on your version of Windows it might be possible with a workaround using a AutoRun.inf file in the root folder of a USB drive. For security reasons this is by default turned off, and in Windows 7 not allowed at all.
To achieve the same effect in a more robust way, you need to create a service that monitors whether your device is connected or not (e.g. iTunesHelper that monitors for connected Apple devices).
The easiest solution is probably a trivial UMDF driver. That's basically a small COM component called when your device is connected.
I want to find the COM port my device got connected in my vc++ program.
upto now i used to scan all the ports from 0 to 15 and send some command if the reply is suitable to me i can confirm that it is the port i am finding.
But this is Taking a lot of time.
anyother solution???
The serial API does not provide for any of the sort of identification that you seem to desire so the only choice that you have is to poll he various ports. If the device is a USB device, you may be able to garnish clues from the friendly name associated with that device (see How do I get the friendly name of a COM port in Windows?).
Problem: Mediate USB traffic/data
I would like to accept inbound traffic on a specific USB port and replicate it exactly as outbound traffic on another specific USB port, in effect accomplishing a USB proxy. By extension, then, the connections need to be two-way. An additional requirement is that the port must be able to fake its identity (vendor ID, product ID, ...) as seen by an external device. Should the given solution also be able to dump/log the raw traffic, that would be fantastic, although not a requirement. Target platforms are Windows and/or Linux (any will do).
Before going on an epic journey and writing a custom driver, which is fairly likely to induce brain damage, I would like to ask if anyone has ever done anything similar, or could possibly conceive of the pieces needed to assemble this puzzle. :)
I don't think this is doable out of the box, without extra hardware.
What kind of device can you expect to connect to the "upstream" port of the proxy? Assuming there's a regular device (let's say a mouse, just as an example) on the "downstream" port, the device at upstream needs to be a USB host in order to handle the USB device in a meaningful way.
But you can't connect the USB port of your computer (which already is the host for all its USB root ports) directly to another computer, that's a total violation of USB's network topology. Both ports contain +5 V power rails, and if you connect those together, you're likely in for a shock. And/or a private fireworks display. Or a trip to your nearest motherboard and/or PSU retailer ...
Also, since USB is quite dynamic and so on, I don't think you can expect the bitstream from one port to be meaningful if repeated out another port, since address information etc might change.
There are 100% software USB analyzers, like http://www.usblyzer.com/, but I'm not so sure about proxies like what you describe.
At my work we have used this Beagle USB Analyzer. It sits between device and host and captures all traffic without interruption. It works in windows and linux and functions even with USB 2.0 highspeed ports.
http://www.totalphase.com/products/beagle_usb480/
Highly recommended.