首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将蓝牙输入设备与计算机连接?

如何将蓝牙输入设备与计算机连接?
EN

Stack Overflow用户
提问于 2015-09-15 13:23:54
回答 1查看 277关注 0票数 0

我已经创建了一个蓝牙输入设备(手写笔),并希望将它连接到Mac和Windows (将来最好是Linux )。

是否有理想的软件/语言可用于创建跨平台应用程序?我已经考虑过为每个应用程序编写本机应用程序,但我不认为应用程序将如此复杂,这是绝对必要的。

应用程序将获取BT设备的输入数据,并使用它在屏幕周围移动光标,并提供单击和压力功能。

提前谢谢你。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-15 13:38:07

我不知道你的设备是怎么设置的。

但是,如果您成功地将至少一个串行接口安装在它上(例如Arduino ),您就可以通过通用串行总线( Universal )将其连接到您的PC上。

在此之后,您将能够打开一个管道到您的设备,以多种语言。

对于Linux和OS来说,C始终是一个很好的选择,使用POSIX库将使它更加容易。

这是我在网上写的一些小贴士,可能会帮助我开始学习。

代码语言:javascript
复制
int init_port (const char * port_name, int baud) {
    /* Main vars */
    struct termios toptions;
    int stream;
    /* Port data */
    speed_t brate = baud;

    if ((stream = apri_porta(port_name)) < 1)
        return 0;

    if (tcgetattr(stream, &toptions) < 0) {
        printf("Error");
        return 0;
    }
    /* INITIALIZING BAUD RATE */
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);

    // IMPORTANT BLOCK OF OPTIONS TO MAKE TX AND RX WORKING
    toptions.c_cflag &= ~PARENB;
    toptions.c_cflag &= ~CSTOPB;
    toptions.c_cflag &= ~CSIZE;
    toptions.c_cflag |= CS8;

    toptions.c_cflag &= ~CRTSCTS;

    toptions.c_cflag |= CREAD | CLOCAL;
    toptions.c_iflag &= ~(IXON | IXOFF | IXANY);

    toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    toptions.c_oflag &= ~OPOST;

    toptions.c_cc[VMIN]  = 0;
    toptions.c_cc[VTIME] = 0;

    tcsetattr(stream, TCSANOW, &toptions);
    if (tcsetattr(stream, TCSAFLUSH, &toptions) < 0) {
        printf("Error");
        return 0;
    }

    return stream;
}

int open_port (const char * port_name) {

    int stream;

    stream = open(port_name, O_RDWR | O_NONBLOCK );

    if (stream == -1)  {
        printf("apri_porta: Impossibile aprire stream verso '%s'\n", port_name);
        return -1;
    }

    return stream;
}

int close_port (int stream) {
    return (close(stream));
}

int write_to_port(int stream, char * str) {
    int len = (int)strlen(str);
    int n = (int)write(stream, str, len);
    if (n != len)
        return 0;
    return 1;
}

int read_from_port(int fd, char * buf, int buf_max, char until) {

    int timeout = 5000;
    char b[1];
    int i=0;

    do {
        int n = (int)read(fd, b, 1);
        if( n==-1) return -1;
        if( n==0 ) {
            usleep( 1 * 1000 );
            timeout--;
            continue;
        }
        buf[i] = b[0];
        i++;
    } while( b[0] != until && i < buf_max && timeout > 0 );

    buf[i] = 0;  // null terminate the string
    return 0;
}

Objective-C (OS )拥有一个很好的库,它的工作就像一个魅力(ORSSerialPort)

但是,如果您想要一个跨平台的解决方案,那么Java是Windows、OS和Linux的最佳选择。

我希望这能帮助你和其他人开始工作。

如果你需要进一步的帮助,可以随时给我下午。

诚挚的问候。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32587286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档