0

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

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

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

先感谢您。

4

1 回答 1

0

我不知道你的设备是如何设置的。

但是,如果您设法在其上安装了至少具有一个串行接口的 PIC(例如Arduino ATMega328 ),则可以通过通用串行总线(USB) 将其连接到您的 PC。

之后,您将能够以多种语言打开连接设备的管道。

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

我写的这个片段在网上采取了一些技巧可能有助于开始

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 X)有一个很好的库,就像一个魅力(ORSSerialPort

但是,如果您想拥有一个跨平台的解决方案,Java对于 Windows、OS X 和 Linux 来说都是最佳选择。

我希望这可以帮助您和其他人入门。

如果您需要进一步的帮助,请随时 PM 我。

此致。

于 2015-09-15T13:38:07.527 回答