func midi_init() error { var ctx libusb.Context err := libusb.Init(&ctx) if err != nil { return err } defer libusb.Exit(ctx) list, err := libusb.Get_Device_List(ctx) if err != nil { return err } defer libusb.Free_Device_List(list, 1) for _, dev := range list { dd, err := libusb.Get_Device_Descriptor(dev) if err != nil { return err } if dd.IdVendor == usb_vid && dd.IdProduct == usb_pid { fmt.Printf("found\n") break } } return nil }
func OpenDpf() (*DPF, error) { vid := uint16(AX206_VID) pid := uint16(AX206_PID) dpf := new(DPF) err := libusb.Init(&dpf.ctx) if err != nil { return nil, err } dpf.hasCtx = true dpf.udev = libusb.Open_Device_With_VID_PID(dpf.ctx, vid, pid) if dpf.udev == nil { return nil, fmt.Errorf("Failed to open device [%04x:%04x] (may be no permission?)", vid, pid) } dpf.hasUdev = true libusb.Set_Auto_Detach_Kernel_Driver(dpf.udev, true) if err = libusb.Claim_Interface(dpf.udev, AX206_INTERFACE); err != nil { return nil, fmt.Errorf("Can't claim interface: %v", err) } dpf.hasClaim = true return dpf, nil }