Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <libusb-1.0/libusb.h>
- #include <stdint.h>
- #include <string.h>
- int main(int argc, char*argv[])
- {
- int res = 0;
- libusb_device_handle* handle = 0;
- int kernelDriverDetached = 0;
- int numBytes = 0;
- int a,b,i;
- unsigned char str[128];
- unsigned char buffer[128];
- res = libusb_init(0);
- if (res != 0) {
- fprintf(stderr, "Error initialising libusb.\n");
- return 1;
- }
- handle = libusb_open_device_with_vid_pid(0, 0x04b4, 0x00f0);
- if (!handle) {
- fprintf(stderr, "Unable to open device.\n");
- return 1;
- }
- if (libusb_kernel_driver_active(handle, 0)) {
- res = libusb_detach_kernel_driver(handle, 0);
- if (res == 0) {
- kernelDriverDetached = 1;
- } else {
- fprintf(stderr, "Error detaching kernel driver.\n");
- return 1;
- }
- }
- res = libusb_claim_interface(handle, 0);
- if (res != 0) {
- fprintf(stderr, "Error claiming interface.\n");
- return 1;
- }
- for (a=0; a<100; a++) {
- memset(str, 0, 128);
- res = libusb_interrupt_transfer(handle, 0x81, str, 128, &numBytes, 1000);
- if (0 == res) {
- b = 0;
- for(i=0; i<32; i++) {
- b += sprintf(&buffer[b], "%.2x ",str[i]);
- }
- buffer[b++] = '\n';
- buffer[b++] = 0;
- printf("%s",buffer);
- } else {
- fprintf(stderr, "Error receiving message %d.\n", a);
- }
- }
- res = libusb_release_interface(handle, 0);
- if (0 != res)
- fprintf(stderr, "Error releasing interface.\n");
- if (kernelDriverDetached)
- libusb_attach_kernel_driver(handle, 0);
- libusb_exit(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement