PC 到 PC USB 通信

发布于 2025-01-06 22:03:02 字数 213 浏览 2 评论 0原文

如何通过 USB 在两台 PC 之间进行通信?我想要一个程序通过 USB 端口将数字发送到另一台 PC,另一个程序将在该 PC 上显示这些数字。我感觉这是不可能的,因为 PC 是主机而不是设备,但 USB 真的有这么有限吗?我实际上讨厌 USB 不像 COM 端口那样只有输入缓冲区和输出缓冲区。您轻松发送和接收。我查看了 libusb,我可以使用它,但我找不到一种方法使一台 PC 成为一个设备。那么这可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城花音 2025-01-13 22:03:02

我找不到将一台 PC 变成设备的方法。那么这可能吗?

不,这在 PC 上是不可能的。 USB 通信始终为主机->设备,而 PC 始终为主机。
您可以购买特殊的 USB2USB 电缆,该电缆中间有一个芯片,两端可作为设备进行通信。

但我只想使用 LAN 电缆。如今,我所知道的每台 PC 都配备了以太网。 TCP/IP 并不太难使用。

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.

以可爱出名 2025-01-13 22:03:02

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.

败给现实 2025-01-13 22:03:02

您需要有一条支持API或SDK的USB数据传输线(也称为USB数据连接线),然后使用以下代码。通信速度比通过 USB 使用 WinSock(TCP/IP) 或通过 USB 串行端口快得多。 USB2.0通讯速度为480Mbps,有效数据通讯速度大于100Mbps,并且可以隔离病毒和网络攻击。

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();


}

看:
参考1参考2

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

蓝眼睛不忧郁 2025-01-13 22:03:02

我也一直在研究这个问题,并在 USB 3 规范中发现允许主机到主机通信。自 USB 3 规范首次发布以来,这一直是 USB 3 的一个功能。这个错误的神话仍然存在,即 USB 3 不允许这样做,因为 USB 2.0 不允许这样做,并且很可能是由于不兼容的电缆烧毁了人们的计算机而使这种情况得以延续。它将需要一根兼容的电缆和正确的软件。我自己很难找到的软件。我也不准备自己编写软件。

兼容的 USB 主机到主机电缆是什么样的?它的两端都有一个 USB-A 连接器。 +5v、D+ 和 D- 引脚不会连接。高速数据线将交叉。我假设如果至少一台计算机具有 USB-C 端口,则标准 C 到 C 电缆或标准 C 到 A 电缆就可以工作。也许不是,主机到主机的连接也需要交叉电缆。我希望硬件足够智能,能够交叉信号,因为它足够智能,不会使电源短路。

有一个 Microsoft 文档描述了如何使用这些主机到主机电缆进行内核调试。这是我能找到的唯一可以在两台计算机之间提供全带宽 USB 3 的东西。这演示了一些非常基本的主机到主机通信。也许有人可以查看现有的代码,以了解如何更普遍地进行这项工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文