Programming a USB transfer cable / talking to a USB device driver

扶醉桌前 提交于 2019-12-03 09:59:38

问题


How do I programmatically access a USB transfer cable (such as Belkin's Easy Transfer Cable) from Windows?

I'm familiar with libusb-win32, but from what I can tell, using that with newer devices and with Windows Vista seems iffy.

I know that Windows Easy Transfer can do this. How do I write code that does the same thing as Windows Easy Transfer?

If there is no canned documentation on how to do this, I'm willing to do some digging, but I don't know where to start. How do I watch what Windows Easy Transfer is doing to find out how it does it? I see that Windows even gives transfer cables their own category in the Device Manager, "Transfer Cable Devices." How do I do low-level communication with one of these these drivers?


回答1:


I found out that Microsoft now offers WinUSB for simple user-mode communication with USB devices. (A WinUSB device driver must first be installed for the device; this is somewhat similar to a libusb-win32 device driver.) WinUSB works on XP (SP2 and above) and Vista.

The Easy Transfer Cable uses WinUSB for its device driver, so I was able to communicate with it by following the example code in Microsoft's WinUSB howto document.




回答2:


You will need to use the low level win32 API to do this. Microsoft has some nice examples here on accessing a Human Interface Device. The transfer cable isn't explicitly an HID like a mouse or keyboard, but it conforms to the HID spec.

For example, to get the name of the USB device you would call

HidD_GetProductString(...)

http://msdn.microsoft.com/en-us/library/ms790920.aspx

There is lots more there, you should definitely take a look at the sample c app that works for all versions of windows from 2000 to Vista.

http://msdn.microsoft.com/en-us/library/dd163258.aspx

Good Luck!




回答3:


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:

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



来源:https://stackoverflow.com/questions/608607/programming-a-usb-transfer-cable-talking-to-a-usb-device-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!