PC to PC USB communication
Asked Answered
G

4

9

How can I communicate between two PC's via USB? I want a program to send numbers trough the USB port to another PC on which another program would show these numbers. I have the feeling that this is impossible because PC's are meant to be hosts and not devices, but is USB truly this limited? I actually hate that USB is not like a COM port which just has an input buffer and an output buffer. You send and receive with ease. I looked at libusb and I could use it, but I can't find a way to make one PC a device. So is it even possible?

Gamesmanship answered 16/2, 2012 at 19:30 Comment(2)
there are special USB cables you can get (search "usb transfer cable") that allow PC-to-PC communication. No idea how they work - presumably they have some special device in between the machines that allows each one to appear to be a device, not a host.Abhorrence
You might hate that USB is not like serial, but to the average consumer it's a godsend because USB allows for the computer to automatically detect what type of device you plugged in and in many cases install the drivers automatically. No more having to enter COM port numbers into configuration utilities.Vitrescence
N
7

I can't find a way to make one PC a device. So is it even possible?

No, this is not possible on a PC. USB communicates always Host->Device, and PC is always Host. You can buy a special USB2USB cable, this has a chip in the middle that communicates as device on both ends.

But I would just use a LAN cable. Every PC I know comes with Ethernet these days. TCP/IP is not too hard to use.

Nasser answered 16/2, 2012 at 20:3 Comment(4)
+1 for LAN and TCP/IP. After you set up a TCP/IP connection, it's very similar to serial port and that you just have an input buffer and an output buffer.Vitrescence
Well, in that case I will have to look into using either Ethernet or that special USB cable. Thank you.Gamesmanship
What about [Enabling USB RNDIS](support.criticallink.com/redmine/projects/arm9-platforms/wiki/… )? RNDIS support allows a PC to talk to a Linux-based embedded system over USB by making the embedded system look like a USB attached Ethernet adapter. And we can access to the RNDIS as a ssh o web server. My questions if we need an special cables as well o just the regular ?Cliftonclim
The issue is LAN usually isn't all that fast compared to USB 3.xSaloon
V
6

If you like serial ports so much, you should just get a USB-to-serial adapter for each computer and then wire them together. These devices create a virtual COM port on your computer and you can use it the same way you would use a normal COM port.

Vitrescence answered 16/2, 2012 at 20:5 Comment(0)
M
5

You need to have an USB data transfer cable (also called USB data link cable) which support API or SDK, then use the following code. Communication speed much faster than using WinSock(TCP/IP) over USB or serial port over USB. USB2.0 communication speed is 480Mbps, effective data communication speeds greater than 100Mbps, and can isolate viruses and network attacks.

void CU2uDlg::OnOK() 
{
BYTE        buf[65530];
LPU2URET    pU2uRet;
BOOL        bRet;
int         ret;
CString     msgstr;

ret = u2u_open();
if (ret == -1){
    AfxMessageBox("Open U2U device Success.");
}else{
    msgstr.Format("Open U2U device fail,return:%d", ret);
    AfxMessageBox(msgstr);
    return;
}

//send data
bRet = u2u_SendData(buf, 65530, ret);
if(!bRet)
{
    msgstr.Format("Send data error,return:%d", ret);
    AfxMessageBox(msgstr);
    return;
}

//receive data
while (1){
    bRet = u2u_RecvData(recvData, dataLen, ret);
    if( !bRet )
    {
        msgstr.Format("Receive data error,return:%d", ret);
        AfxMessageBox(msgstr);
        u2u_close();
        return;
    }else{
        break;
    }
}
u2u_close();


}

See: Reference1, Reference2

Mizell answered 11/11, 2013 at 8:25 Comment(0)
A
2

I have been looking at this too and I found in the USB 3 spec that host to host communication is allowed. And this has been a feature of USB 3 since the USB 3 spec was first published. This erroneous myth persists that USB 3 does not allow this because USB 2.0 did not allow it and likely this is perpetuated by non compliant cables frying peoples’ computers. It will take a compliant cable and the right software. Software that I’m having difficulty finding myself. Software that I’m not prepared to write myself either.

What does a compliant USB host to host cable look like? It will have a USB-A connector on both ends. The +5v, D+, and D- pins will NOT be connected. The high speed data lines will be crossed over. I assume a standard C to C cable or standard C to A cable would work if at least one computer has a USB-C port. Perhaps not and a host to host connection needs a crossover cable too. I would hope the hardware is smart enough to crossover the signals considering that it’s smart enough not to short out power supplies.

There is a Microsoft document describing how to use these host to host cables for kernel debug. That is the only thing I could find on this that gave full bandwidth USB 3 between two computers. This demonstrates some very rudimentary host to host communications. Perhaps some one could look at the code that exists to get an idea on how to make this work more generally.

Augment answered 19/12, 2019 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.