PC to PC USB communication
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.
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.
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