简体   繁体   English

我们可以通过USB线缆将数据通过USB Host API传输到PC吗?

[英]Can we transfer data through USB Host API to PC via USB cable?

Please help me on this, 请帮帮我,

In my project I need to transfer data from android device(3.0 and above) to PC via USB cable without depending on USB debugging mode option(USB debugging option should not be selected). 在我的项目中,我需要通过USB线将数据从Android设备(3.0及以上版本)传输到PC,而不依赖于USB调试模式选项(不应选择USB调试选项)。

So is this possible to transfer data to PC with USB host API? 那么可以通过USB主机API将数据传输到PC吗?

Thanks in advance. 提前致谢。

You can, just the way the cardock works. 你可以,就像卡罗克的工作方式一样。
The only difference the USB host function is that when android is in host mode it supplies the power. USB主机功能的唯一区别是,当android处于主机模式时,它提供电源。
This is device dependent and not API lvl dependent. 这取决于设备,而不依赖于API lvl。
But you don't want the host function, as the pc is the host. 但是你不需要主机功能,因为pc是主机。
You want to be in accessory mode. 你想要处于配件模式。
For more info, check: Accessory mode 有关详细信息,请检查: 附件模式

You need to have an USB data transfer cable (also called USB data link cable) which 您需要有一条USB数据传输电缆(也称为USB数据链接电缆)

support API or SDK, then use the following code: 支持API或SDK,然后使用以下代码:

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 参考文献1参考文献2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM