前几天,又开了一个新项目,发现读取一个USB dongle的版本号信息的时候读取不出来,最后发现是一个新的dongle
于是需要修改native层的C++应用程序:
1.首先看/dev目录下的hidraw设备节点有哪些:
fd = open(DEVICE_NFC_PATH, O_RDWR /*| O_NONBLOCK*/);
if (fd < 0){
printf("Maybe the device have been reboot\n");
int i = 0;
for ( ;i < 20; i++) {
sprintf(filename, "/dev/hidraw%d", i);
printf("\n print filename =%s\n",filename);
fd = open(filename, O_RDWR /*| O_NONBLOCK*/);
if (fd < 0){
printf("can't find the device !!\n");
return 0;
}
if (freespace_checkDeviceInfo(fd , filename )) {
printf("Found Freespace device interface.\n");
return 1;
}
close(fd);
}
}
else if (freespace_checkDeviceInfo(fd , filename )) {
printf("Found Freespace device interface.\n");
return 1;
}
2.然后针对每个设备节点,判断是否是符合条件的设备:
int rc = ioctl(hid_device->_fd, HIDIOCGRAWINFO, &info);
if (rc < 0) {
perror("HIDIOCGRAWINFO");
goto fail;
}
printf("HID device info %04x:%04x:%04x is\n", info.bustype,info.vendor, info.product);
后面针对设备信息进行检测的时候,发现是个新的设备,因为可以获取到新设备的节点信息,所以就在程序中增加了这个dongle的检测条件使其可以通过检测。
因为通信协议是一样的,所以添加这个设备后,利用同样的通信协议将获取dongle信息的命令写到设备节点,通过文件IO便可以得到结果了。
rc=fdp_->waitForReadReady(1000, &readReady);
if(readReady)
rc = read(fd_, ProRdBuf, sizeof(ProRdBuf));
if(rc<0){
printf("can't read dongle's version\n");
return -1;
}
_cmd->_return_value = ProRdBuf;