Esempio n. 1
0
/*
 * RFID 硬件检测
 * 返回值说明:1,返回-1表示硬件不支持或无硬件;2,返回-2表示无卡;3,返回1表示读到卡的UID
 * 
 */
JNIEXPORT jint JNICALL Java_com_lyt_boruan_Interface_Rfidcheck(JNIEnv *pJE,
		jobject jo) {
	int i = 0;
	int flag = -1;
	int open = openFM1702(); //1,打开RFID
	LOGD("RFID test..... %d\n", open);
	int select = selectFM1702(); //2,选择类型
	LOGD("RFID test..... %d\n", select);
	if (select == -43) {

		flag = -1;
		return flag;
	}

	for (i = 0; i < 5; i++) {
		int uid = readcard(); ///1 or -1;//3,读卡测试
		if (uid == 1) {
			LOGD("RFID---uid: RFID open\n");
			flag = 1;
			closeFM1702(); //4,别忘记关闭当前测试
			return 1;
		} else {
			if (uid == -1) { //硬件错误
				flag = -1;
				LOGD("RFID---uid: no hw support!!!\n");
			}
			flag = -2; //无卡
		}
	}

	closeFM1702(); //4,别忘记关闭当前测试

	return flag;

}
Esempio n. 2
0
int main()
{
  libusb_context *context;
  libusb_device_handle *handle;
  int configuration_value = 1, interface_number = 1, rv;

  rv = libusb_init(&context);
  if (rv != 0)
    {
      usbx_strerror(rv);
      return -1;
    }
  libusb_setlocale("zh");
  libusb_set_debug(context, LIBUSB_LOG_LEVEL_DEBUG);

  handle = libusb_open_device_with_vid_pid(context, 0x16C0, 0x06EA);
  if (!handle)
    {
      libusb_exit(context);
      return -1;
    }
  libusb_set_auto_detach_kernel_driver(handle, 1);

  rv = libusb_set_configuration(handle, configuration_value);
  if (rv != 0)
    {
      usbx_strerror(rv);
      libusb_close(handle);
      libusb_exit(context);
      return -1;
    }
  rv = libusb_claim_interface(handle, interface_number);
  if (rv != 0)
    {
      usbx_strerror(rv);
      libusb_close(handle);
      libusb_exit(context);
      return -1;
    }
  readcard(handle);

  libusb_release_interface(handle, interface_number);
  libusb_close(handle);
  libusb_exit(context);
  return 0;
}