Bluetooth 如何将蓝牙输入设备连接到计算机?
我已经创建了一个蓝牙输入设备(触控笔),并希望将其连接到Mac和Windows(将来最好是Linux) 是否有理想的软件/语言用于创建跨平台应用程序?我已经考虑过为每个应用程序编写本机应用程序,但我不认为应用程序会如此复杂以至于这是绝对必要的 应用程序将获取BT设备的输入数据,并使用它在屏幕上移动光标,并提供点击和压力功能Bluetooth 如何将蓝牙输入设备连接到计算机?,bluetooth,cross-platform,native,input-devices,Bluetooth,Cross Platform,Native,Input Devices,我已经创建了一个蓝牙输入设备(触控笔),并希望将其连接到Mac和Windows(将来最好是Linux) 是否有理想的软件/语言用于创建跨平台应用程序?我已经考虑过为每个应用程序编写本机应用程序,但我不认为应用程序会如此复杂以至于这是绝对必要的 应用程序将获取BT设备的输入数据,并使用它在屏幕上移动光标,并提供点击和压力功能 提前谢谢。我不知道您的设备是如何设置的 但是,如果您设法在其上安装至少有一个串行接口的PIC(如Arduino ATMega328),则可以通过通用串行总线(USB)将其连接
提前谢谢。我不知道您的设备是如何设置的 但是,如果您设法在其上安装至少有一个串行接口的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;
}
int init_端口(常量字符*端口名称,int波特){
/*主要变量*/
结构术语;
int流;
/*端口数据*/
速度=波特;
如果((流=apri\u porta(端口名称))<1)
返回0;
if(tcgetattr(流和顶选项)<0){
printf(“错误”);
返回0;
}
/*初始化波特率*/
cfsetispeed(和toptions,brate);
cfsetospeed(和Topions,brate);
//使TX和RX工作的重要选项块
toptions.c_cflag&=~PARENB;
toptions.c_cflag&=~CSTOPB;
toptions.c_cflag&=~CSIZE;
Topions.c|u cflag |=CS8;
toptions.c_cflag&=~CRTSCTS;
toptions.c|u cflag |=CREAD | CLOCAL;
toptions.c|u iflag&=~(IXON | IXOFF | IXANY);
toptions.c|lflag&=~(ICANON | ECHO | ECHO | ISIG);
toptions.c_of lag&=~OPOST;
toptions.c_cc[VMIN]=0;
toptions.c_cc[VTIME]=0;
tcsetattr(流、TCSANOW和toptions);
if(tcsetattr(流、TCSAFLUSH和toptions)<0){
printf(“错误”);
返回0;
}
回流;
}
int open_端口(常量字符*端口名称){
int流;
流=打开(端口名称,O_RDWR | O_非块);
如果(流==-1){
printf(“apri\u porta:不可能的aprire流与“%s”\n”,端口名);
返回-1;
}
回流;
}
int close_端口(int流){
返回(关闭(流));
}
int-write_-to_端口(int-stream,char*str){
int len=(int)strlen(str);
int n=(int)写入(流、str、len);
如果(n!=len)
返回0;
返回1;
}
从端口读取的整数(整数fd,字符*buf,整数buf\u max,字符直到){
int超时=5000;
charb[1];
int i=0;
做{
int n=(int)读(fd,b,1);
如果(n==-1)返回-1;
如果(n==0){
usleep(1*1000);
超时--;
持续
}
buf[i]=b[0];
i++;
}while(b[0]!=until&&i0);
buf[i]=0;//null终止字符串
返回0;
}
Objective-C
(OS X)有一个很好的库,它的工作方式很有魅力()
但是,如果您想要一个跨平台的解决方案,Java
是Windows、OS X和Linux的最佳选择
我希望这能帮助你和其他人开始
如果你需要进一步的帮助,请随时PM我
致以最诚挚的问候。谢谢您的回复!蓝牙仍然是一个可行的选择,但如果设置正确与这些语言虽然正确?对于这样一个非常简单的桌面应用程序(与word等程序相比),您认为编写本机应用程序还是只使用Java是值得的?我想先权衡利弊。C在任何地方都可以编译:在带有IDE的Windows上,在基于Unix的系统上,通过GCC或CLANG直接从终端进行编译。现在很重要的一点是要准确地了解您想要什么,据我所知,您需要某种后台实用程序,它可以从蓝牙串行接口读取数据并移动光标,提供单击支持。为此,如果在windows或Liunx上工作,请继续使用Java。串行接口很简单,鼠标事件也很简单。在OSX上使用Obj-C。它被认为可以在Mac上执行任何您需要的操作。如果我有点困惑,很抱歉,但我想说的是,从串行接口读取数据和在屏幕上移动光标都是简单的任务。那么选择就看你了。不,那太棒了——非常感谢你的帮助!请原谅提供的代码,函数名是用我的语言编写的,在将其移植到英语时,我忘记更改一些调用()