Page 1 of 2

Smart reverse USB hub

PostPosted: April 15th, 2012, 9:13 am
by LucaNonato
Hi!

Tried searching the forums but found nothing... My idea was, as you can read from the subj, a "Smart reverse USB hub". I'll try to explain:

- Reverse: will be used to connect 1 usb device to many hosts (PCs, macs, NAS, routers maybe?)
- smart: the smart part is that if the hub detects a powered port, it connects the device to that specific port. Hopefully it would have a priority so that if port 1 is powered then the device goes there, otherwise if the 2nd port is powered this device will be connected to the device and so on...

Its main purpose will be connecting the UPS to either my NAS/PC/Mac, depending on what's turned on... Does make sense?

Maybe 3 or 4 USB ports should be enough... What do you think? Can it be done?


Cheers!
Luca

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 12:49 pm
by st2000
USB is far far more tricky then a RS232 serial port. What you need to do - right off the bat - is to see how each of the hosts reacts to the removal and installation of the UPS/USB peripheral. If each host will tolerate the removal of the UPS/USB peripheral and, more importantly, if it will enumerate the installation of the UPS/USB peripheral.** Not only that, but say you accidentally turn on then off a higher priority USB host and your "smart switch" follows moving the UPS/USB peripheral to the higher priority USB host. Will the lower priority host recover control of the UPS/USB peripheral? Will the USB peripheral have been gone long enough for the host to "see the event"? Will the UPS/USB peripheral think it has been assigned a different USB address while attached to the higher priority USB host?

Ah, there's another good one! Can a USB peripheral be "re-enumerated" after being used with a different USB host? I am thinking it can, but what events must take place in order for that to happen? Is there a minimum time period that needs to be adhered to? Lot of questions.

I would recommend this book: http://www.lvr.com/usbc.htm

You can buy it a amazon.com if you like. Jan has a USB host book too. But I think that might be more than you need for this project.

Just guessing, but I think if you make it so your smart switch will switch slow enough you won't drive your hosts mad. That is, if you emulate physically pulling and plugging the USB cable between peripheral and different hosts. Remember, that means tri stating the pins on the USB host as well as the USB peripheral between connections. And no fair making switches until you are sure the higher priority host is going to stay on. That probably means either bi-lateral MOSFET switches or relays on ALL FOUR pins including the power pins.

**I think you listed a non-dedicated USB host device. What I mean by that is that some devices like a PC may be busy off doing other stuff (like checking for viruses). That is, it may take longer (some times) to recognize a USB peripheral. Keep that in mind when considering how slow you need to switch, if switching between hosts is possible, so that the event will occur in a (mostly) dependable fashion.


Edit: added later...

I should add that I have seen Windows do the "stupid thing" when a USB peripheral is removed and re-installed over and over again. That is, I have seen Windows assigned a higher and higher USB address to the re-installed peripheral. Sometimes this number gets so large that the peripheral's own software can no longer access the USB device (the software can not set the USB address that high). I think the only recourse is to re-boot the Windows machine. But isn't that always the answer w/Windows?

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 3:10 pm
by k-ww
What about a KVM switch - I've seen them for USB keyboards and mice.

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 3:20 pm
by st2000
I have always had trouble w/KVM switches. Perhaps it's the brand I have. But if the "right" computer is not on, the switch has no power and will not operate. Further (now it gets obfuscated) if the "wrong" computer is powered up first, then the lack of a keyboard (remember my KVM apparently only draws power from the "right" computer) throws the "wrong" computer into a tail spin.

So, in my setup, the server is the "right" computer and I never turn it off. Done.

On top of that, 2:1 KVM switch must be a commodity item 'cause they are cheap. However just going to 3:1 will cost you body parts. And I think that is what the OP wanted, 3:1.

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 4:53 pm
by LucaNonato
k-ww wrote:What about a KVM switch - I've seen them for USB keyboards and mice.
Yes, but as far as i know you have to manually choose to which port the mouse/keyboard are attached to... Well, this would be something close to what i have in mind, you're not wrong, but it would be awesome being able to connect all the devices and forget about it... But i'll give it a try if they're not too expensive...

I'm just not sure about the power: old PS/2 KVM switches required either an external PSU or the 1st device on (read: current from the keyboard on the 1st device) or it wouldn't work properly, and i would like not to have another power supply just for something that should work fine - i think - simply getting the watts from the USB port...

Cheers!
Luca

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 5:07 pm
by LucaNonato
st2000 wrote:On top of that, 2:1 KVM switch must be a commodity item 'cause they are cheap. However just going to 3:1 will cost you body parts. And I think that is what the OP wanted, 3:1.
Exactly: i (currently) need 3 ports because the UPS should be connected to either a PC, an iMac or a Synology NAS...

Edit: your other post requires a more complex reply, see you tomorrow... :) Good night to everyone...

Re: Smart reverse USB hub

PostPosted: April 15th, 2012, 6:41 pm
by UAirLtd
What you've described is basically a USB switch. These switches switch one USB device between multiple computers. I think the more expensive USB switches enumerate as a simple USB HID device on all the ports, and automatically switch the input over if only one of those is enabled. The cheap ones very crudely connects and disconnects the USB device via relays.

Nevertheless, the option remains for you to simply modify a cheaper USB switch to automatically switch inputs based on which ones are powered. I've modified a USB switch to include an IR receiver for another Hackaday user: http://hackaday.com/2011/09/29/remote-c ... sb-switch/ and viewtopic.php?f=3&t=1166 it is straightforward to do a similar modification to detect powered ports instead (the +5V inputs already have diodes installed, so it's a simple case of pulling one end low with a resistor to avoid the voltage rising due to reverse leakage).

Re: Smart reverse USB hub

PostPosted: June 15th, 2012, 12:48 pm
by LucaNonato
UAirLtd wrote:What you've described is basically a USB switch. These switches switch one USB device between multiple computers.
I admin that i haven't checked a lot, but i always found - and owned - USB hubs to connect more devices to one computer, and i assumed that there was nothing for the opposite purpose... I'l try to get one and find out if it can fit my need... Thanks...


Cheers!

Re: Smart reverse USB hub

PostPosted: June 15th, 2012, 4:44 pm
by st2000
One more thought occurs to me.

Most people have no idea how complex the conversation is between a USB host and peripheral. And, still more don't realize how different the conversation can be (that a host is expected to carry on) between, say, a Thumb Drive and a Mouse.

Without knowing what type of USB peripheral your UPS is, we are all literally taking shots in the dark.

If your UPS is masquerading as a HID, then the KVM switch idea has merit. However, if it is not, well, I'm not sure what will happen. Think of it this way: You are at your bank making a transaction. Suddenly, in the middle of the transaction, you walk away. The teller does not know what to do. In fact, he forwards all your paper work to the in box of the bank controller (essentially the error log file) and puts a lock on your account. In short, until you reboot your computer the USB port may be off limits. In some cases, such as a Thumb Drive (mass storage device), the memory of the USB device may be compromised as well.

Re: Smart reverse USB hub

PostPosted: July 25th, 2017, 3:50 am
by LucaNonato
Well, looks finally - since at least a year, sorry for the delay :) - someone made a USB switch like the one i was talking about:
  • https://www.iogear.com/usb-switch.htm
  • Plugable USB 2.0 Switch for One-Button Swapping of USB Device/Hub Between Two Computers (A/B switch)
and many others... :)