handle error OpenDeviceWithVidPid and add GetStringDescriptor

This commit is contained in:
nodtem66
2015-03-04 01:32:24 +07:00
parent 4bf19c7f86
commit f3b93aa5fa
2 changed files with 25 additions and 0 deletions

View File

@@ -112,8 +112,17 @@ func (c *Context) ListDevices(each func(desc *Descriptor) bool) ([]*Device, erro
// OpenDeviceWithVidPid opens Device from specific VendorId and ProductId.
// If there are any errors, it'll returns at second value.
func (c *Context) OpenDeviceWithVidPid(vid, pid int) (*Device, error) {
handle := C.libusb_open_device_with_vid_pid(c.ctx, (C.uint16_t)(vid), (C.uint16_t)(pid))
if handle == nil {
return nil, ERROR_NOT_FOUND
}
dev := C.libusb_get_device(handle)
if dev == nil {
return nil, ERROR_NO_DEVICE
}
desc, err := newDescriptor(dev)
// return an error from nil-handle and nil-device