Created
January 19, 2016 10:01
-
-
Save b4284/b4bdc4d9d7d18e947c5a 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 usb_send_recv send recv = | |
| let device = USB.open_device_with ~vendor_id:0x0000 | |
| ~product_id:0x0000 in | |
| let t = | |
| USB.claim_interface device 0 | |
| >>= | |
| fun u -> ( | |
| USB.bulk_send ~handle:device | |
| ~endpoint:0x01 send 0 (String.length send) | |
| ) | |
| >>= | |
| fun s -> ( | |
| if s > 0 then | |
| USB.bulk_recv ~handle:device ~endpoint:0x81 | |
| recv 0 (String.length recv) | |
| else | |
| return (-1) | |
| ) | |
| >>= | |
| fun l -> return (USB.release_interface device 0, l) | |
| >>= | |
| fun (rel, l) -> ( | |
| let _ = (rel >>= (fun u -> return @@ USB.close device)) | |
| in return l | |
| ) | |
| in Lwt_main.run t | |
| ;; | |
| let cmd = "\x00\x00\x00\x00\x00\x00\x00\x00" | |
| and buf = String.make 500 (char_of_int 0) in | |
| let len = usb_send_recv cmd buf in | |
| len | |
| |> 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 | |
| ;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment