我正在尝试使用 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;
}
}
}
}
return 0;
}
如果有人有任何想法,到目前为止我对此一无所知。如果有任何帮助,我可以运行screen /dev/tty.KDC1
并且扫描仪上扫描的任何条形码都会出现在终端中,我无法对数据执行任何操作。
Jud
这行:
while((res = read(fd,buf,255)) == 0);
不做你认为它做的事。那是一个while
循环体为空。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)