コード例 #1
0
ファイル: wbt1372.c プロジェクト: eform/eform
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;
}
コード例 #2
0
ファイル: yusb.c プロジェクト: emmt/yusb
static void initialize(void)
{
  if (ctx == NULL) {
    int code = libusb_init(&ctx);
    if (code != 0) {
      if (ctx != NULL) {
        y_error("*** ASSERTION FAILED *** non NULL context on libusb_init failure");
      }
      failure(NULL, code);
    }
    if (ctx == NULL) {
      y_error("*** ASSERTION FAILED *** NULL context on libusb_init success");
    }
    ycall_on_quit(finalize);
    libusb_set_debug(ctx, LIBUSB_LOG_LEVEL_NONE);
    libusb_setlocale("en");
  }
}
コード例 #3
0
ファイル: xusb.c プロジェクト: BurhanEyuboglu/libusb
int main(int argc, char** argv)
{
	bool show_help = false;
	bool debug_mode = false;
	const struct libusb_version* version;
	int j, r;
	size_t i, arglen;
	unsigned tmp_vid, tmp_pid;
	uint16_t endian_test = 0xBE00;
	char *error_lang = NULL, *old_dbg_str = NULL, str[256];

	// Default to generic, expecting VID:PID
	VID = 0;
	PID = 0;
	test_mode = USE_GENERIC;

	if (((uint8_t*)&endian_test)[0] == 0xBE) {
		printf("Despite their natural superiority for end users, big endian\n"
			"CPUs are not supported with this program, sorry.\n");
		return 0;
	}

	if (argc >= 2) {
		for (j = 1; j<argc; j++) {
			arglen = strlen(argv[j]);
			if ( ((argv[j][0] == '-') || (argv[j][0] == '/'))
			  && (arglen >= 2) ) {
				switch(argv[j][1]) {
				case 'd':
					debug_mode = true;
					break;
				case 'i':
					extra_info = true;
					break;
				case 'w':
					force_device_request = true;
					break;
				case 'b':
					if ((j+1 >= argc) || (argv[j+1][0] == '-') || (argv[j+1][0] == '/')) {
						printf("   Option -b requires a file name\n");
						return 1;
					}
					binary_name = argv[++j];
					binary_dump = true;
					break;
				case 'l':
					if ((j+1 >= argc) || (argv[j+1][0] == '-') || (argv[j+1][0] == '/')) {
						printf("   Option -l requires an ISO 639-1 language parameter\n");
						return 1;
					}
					error_lang = argv[++j];
					break;
				case 'j':
					// OLIMEX ARM-USB-TINY JTAG, 2 channel composite device - 2 interfaces
					if (!VID && !PID) {
						VID = 0x15BA;
						PID = 0x0004;
					}
					break;
				case 'k':
					// Generic 2 GB USB Key (SCSI Transparent/Bulk Only) - 1 interface
					if (!VID && !PID) {
						VID = 0x0204;
						PID = 0x6025;
					}
					break;
				// The following tests will force VID:PID if already provided
				case 'p':
					// Sony PS3 Controller - 1 interface
					VID = 0x054C;
					PID = 0x0268;
					test_mode = USE_PS3;
					break;
				case 's':
					// Microsoft Sidewinder Precision Pro Joystick - 1 HID interface
					VID = 0x045E;
					PID = 0x0008;
					test_mode = USE_HID;
					break;
				case 'x':
					// Microsoft XBox Controller Type S - 1 interface
					VID = 0x045E;
					PID = 0x0289;
					test_mode = USE_XBOX;
					break;
				default:
					show_help = true;
					break;
				}
			} else {
				for (i=0; i<arglen; i++) {
					if (argv[j][i] == ':')
						break;
				}
				if (i != arglen) {
					if (sscanf(argv[j], "%x:%x" , &tmp_vid, &tmp_pid) != 2) {
						printf("   Please specify VID & PID as \"vid:pid\" in hexadecimal format\n");
						return 1;
					}
					VID = (uint16_t)tmp_vid;
					PID = (uint16_t)tmp_pid;
				} else {
					show_help = true;
				}
			}
		}
	}

	if ((show_help) || (argc == 1) || (argc > 7)) {
		printf("usage: %s [-h] [-d] [-i] [-k] [-b file] [-l lang] [-j] [-x] [-s] [-p] [-w] [vid:pid]\n", argv[0]);
		printf("   -h      : display usage\n");
		printf("   -d      : enable debug output\n");
		printf("   -i      : print topology and speed info\n");
		printf("   -j      : test composite FTDI based JTAG device\n");
		printf("   -k      : test Mass Storage device\n");
		printf("   -b file : dump Mass Storage data to file 'file'\n");
		printf("   -p      : test Sony PS3 SixAxis controller\n");
		printf("   -s      : test Microsoft Sidewinder Precision Pro (HID)\n");
		printf("   -x      : test Microsoft XBox Controller Type S\n");
		printf("   -l lang : language to report errors in (ISO 639-1)\n");
		printf("   -w      : force the use of device requests when querying WCID descriptors\n");
		printf("If only the vid:pid is provided, xusb attempts to run the most appropriate test\n");
		return 0;
	}

	// xusb is commonly used as a debug tool, so it's convenient to have debug output during libusb_init(),
	// but since we can't call on libusb_set_debug() before libusb_init(), we use the env variable method
	old_dbg_str = getenv("LIBUSB_DEBUG");
	if (debug_mode) {
		putenv("LIBUSB_DEBUG=4");	// LIBUSB_LOG_LEVEL_DEBUG
	}

	version = libusb_get_version();
	printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
	r = libusb_init(NULL);
	if (r < 0)
		return r;

	// If not set externally, and no debug option was given, use info log level
	if ((old_dbg_str == NULL) && (!debug_mode))
		libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_INFO);
	if (error_lang != NULL) {
		r = libusb_setlocale(error_lang);
		if (r < 0)
			printf("Invalid or unsupported locale '%s': %s\n", error_lang, libusb_strerror((enum libusb_error)r));
	}

	test_device(VID, PID);

	libusb_exit(NULL);

	if (debug_mode) {
		snprintf(str, sizeof(str), "LIBUSB_DEBUG=%s", (old_dbg_str == NULL)?"":old_dbg_str);
		str[sizeof(str) - 1] = 0;	// Windows may not NUL terminate the string
	}

	return 0;
}
コード例 #4
0
ファイル: lq90kp.c プロジェクト: eform/eform
int main()
{
    libusb_context *context;
    libusb_device_handle *handle;
    int configuration_value = 1, interface_number = 0, rv;
    char *p;

    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, 0x04B8, 0x0005);
    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;
    }
    /*
    putstring(handle, (unsigned char*) "\x1B\x40", 2);
    putstring(handle, (unsigned char*) "\x1B\x4A\x10", 3);
    putstring(handle, (unsigned char*) "hello\n", 5);
    putstring(handle, (unsigned char*) "\x1B\x6A\x10", 3);
    */

    //putstring(handle, (unsigned char*) "\x1B\x194", 3);
    putstring(handle, (unsigned char*) "hello\n", 6);
    /*
    p = malloc(10000);
    memset(p, ' ', 10000);
    putstring(handle, p, 10000);
    */
    //getstring(handle);
    putstring(handle, (unsigned char*) "\x07", 1);
    //putstring(handle, (unsigned char*) "\x18", 1);
    putstring(handle, (unsigned char*) "\x0C", 1);
    //putstring(handle, (unsigned char*) "\x1B\x190", 3);
    //putstring(handle, (unsigned char*) "\x1B\x40", 2);
    //putstring(handle, (unsigned char*) "\x1B\x4F", 2);

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