我已经创建了一个蓝牙输入设备(手写笔),并希望将其连接到Mac和Windows(将来最好是Linux)。
是否有用于创建跨平台应用程序的理想软件/语言?我曾考虑为每个应用程序编写本机应用程序,但我认为应用程序不会如此复杂以至于绝对必要。
该应用程序将获取BT设备的输入数据,并使用它在屏幕上移动光标并提供单击和按压功能。
先感谢您。
我不知道您的设备是如何设置的。
但是,如果您设法在其上放置具有至少一个串行接口的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而言,它都是最佳选择。
希望这对您和其他人有所帮助。
如果您需要进一步的帮助,请随时与我联系。
最好的祝福。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句