Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <libusb-1.0/libusb.h>
- const int interface_number = 0;
- int main(int argc, char** argv) {
- int result;
- result = libusb_init(NULL);
- if (result) {
- printf("Failed to initialize libusb: %s\n", libusb_error_name(result));
- return EXIT_FAILURE;
- }
- libusb_device_handle* device_handle = libusb_open_device_with_vid_pid(NULL, 0x2104, 0x0313);
- if (!device_handle) {
- printf("Failed to open device\n");
- return EXIT_FAILURE;
- }
- libusb_set_auto_detach_kernel_driver(device_handle, true);
- result = libusb_claim_interface(device_handle, interface_number);
- if (result) {
- printf("Failed to claim interface: %s\n", libusb_error_name(result));
- return EXIT_FAILURE;
- }
- uint8_t write_buffer[] = {
- 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x1b,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x58,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
- 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00,
- 0x00, 0x00, 0x03
- };
- int length;
- result = libusb_bulk_transfer(device_handle, 0x5, write_buffer, sizeof(write_buffer), &length, 1000);
- if (result) {
- printf("Failed to write data: %s\n", libusb_error_name(result));
- return EXIT_FAILURE;
- }
- uint8_t read_buffer[32] = {0};
- result = libusb_bulk_transfer(device_handle, 0x83, read_buffer, sizeof(read_buffer), &length, 1000);
- if (result) {
- printf("Failed to read data: %s\n", libusb_error_name(result));
- return EXIT_FAILURE;
- }
- libusb_release_interface(device_handle, interface_number);
- libusb_close(device_handle);
- libusb_exit(NULL);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment