PC到移动USB通信

PC到移动USB通信,usb,Usb,我在我的电脑上使用Windows 7作为操作系统。我希望创建一个应用程序,在其中我将以编程方式向手机发送AT命令。 到目前为止,我希望通过PC和手机之间的USB数据线连接实现这一目标。我最初的方法是使用JAVA。虽然我很快意识到,大多数用于JAVA和USB端口之间通信的API开发对于windows来说已经过时了,而且这些API都不支持Windows7。 有人能建议哪种语言最适合这样做吗 谢谢, Ishan Aggarwal对于Android要创建与PC的连接,您需要使用adb命令(Android

我在我的电脑上使用Windows 7作为操作系统。我希望创建一个应用程序,在其中我将以编程方式向手机发送AT命令。 到目前为止,我希望通过PC和手机之间的USB数据线连接实现这一目标。我最初的方法是使用JAVA。虽然我很快意识到,大多数用于JAVA和USB端口之间通信的API开发对于windows来说已经过时了,而且这些API都不支持Windows7。 有人能建议哪种语言最适合这样做吗

谢谢,
Ishan Aggarwal

对于Android要创建与PC的连接,您需要使用
adb
命令(Android SDK)转发相同的端口,如:

Java中似乎:

private int port = 7612;
....

/**
 * Runs the android debug bridge command of forwarding the ports
 *
 */
private void execAdb() {
    // run the adb bridge
    try {
        String runP = "adb forward tcp:" + port + " tcp:" + port + "";

        System.out.println("Run command through cmd: " + runP);



        Process p=Runtime.getRuntime().exec(runP);
        Scanner sc = new Scanner(p.getErrorStream());
        if (sc.hasNext()) {
            while (sc.hasNext()) System.out.println(sc.next());
            System.out.println("Cannot start the Android debug bridge");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
之后,您可以实现任何TCP客户机/服务器代码,因为端口已定义,您可以使用默认IP,如:127.0.0.1


对于iOS,请使用Objective C lang。

您没有透露设备类型。我要连接到PC的设备是手机。我不希望品牌的限制,虽然我想从黑莓开始。也许有点晚,但目前我的工作应该支持Windows侧(它写在C,但你可以在VS中创建一个C++项目),我知道有可能将它集成到C。让我知道这是否有帮助,我会发布更准确的答案。请看我在这篇文章中的答案嗨,马克西姆,谢谢你的帮助,尽管我心里有几个问题:1。您使用了端口号7612,是否有具体原因?这个端口定义为USB端口吗?我使用这个端口作为自由端口(总是)。从来没有遇到过问题
private int port = 7612;
....

/**
 * Runs the android debug bridge command of forwarding the ports
 *
 */
private void execAdb() {
    // run the adb bridge
    try {
        String runP = "adb forward tcp:" + port + " tcp:" + port + "";

        System.out.println("Run command through cmd: " + runP);



        Process p=Runtime.getRuntime().exec(runP);
        Scanner sc = new Scanner(p.getErrorStream());
        if (sc.hasNext()) {
            while (sc.hasNext()) System.out.println(sc.next());
            System.out.println("Cannot start the Android debug bridge");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}