Created
January 19, 2016 09:15
-
-
Save b4284/51cef5e05fc8c75c523d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open Core.Std | |
| open Lwt | |
| let cmd = "\x00\x00\x00\x00\x00\x00\x00\x00";; | |
| let buf = String.make 500 (char_of_int 0);; | |
| let device = USB.open_device_with ~vendor_id:0x0CA6 ~product_id:0xA010 in | |
| let t = | |
| USB.claim_interface device 0 | |
| >>= | |
| fun u -> ( | |
| USB.bulk_send ~handle:device | |
| ~endpoint:0x01 cmd 0 (String.length cmd) | |
| ) | |
| >>= | |
| fun s -> ( | |
| if s > 0 then | |
| USB.bulk_recv ~handle:device ~endpoint:0x81 buf 0 500 | |
| else | |
| return (-1) | |
| ) | |
| >>= | |
| fun r -> ( | |
| r | |
| |> String.slice buf 0 | |
| |> String.to_list | |
| |> List.map ~f:(fun c -> Printf.sprintf "%02X" @@ int_of_char c) | |
| |> String.concat ~sep:" " | |
| |> print_endline | |
| |> return | |
| ) | |
| >>= | |
| fun u -> USB.release_interface device 0 | |
| >>= | |
| fun u -> return @@ USB.close device | |
| in Lwt_main.run t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment