Android 设备节点查询及设备信息读取

前几天,又开了一个新项目,发现读取一个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;




 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值