我正在尝试使用C从蓝牙条码扫描器(KDC300)读取数据.这是我到目前为止的代码,程序成功建立了与扫描仪的蓝牙连接,但是当扫描条形码时,没有输入显示屏幕(最终将完成更多的数据,但我们必须先让它工作,对吧).
这是程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
int main (int argc, const char * argv[]) {
// define vars
int STOP = 0;
//char buf[255];
if(argv[1])
{
int fd = open("/dev/tty.KDC1", O_RDONLY);
if(fd == -1)
{
printf("%s", strcat("Unable to open /dev/tty.", argv[1]));
}
int res;
while(STOP == 0)
{
while((res = read(fd,buf,255)) == 0);
{
if(res > 0)
{
buf[res]=0;
printf("%s:%d\n", buf, res);
if(buf[sizeof(buf)]=='\n') break;
}
}
}
} …Run Code Online (Sandbox Code Playgroud)