示例#1
0
文件: eeprom.go 项目: sstallion/go
// First returns the first supported device attached to the host. Unlike Walk,
// the returned Device is opened automatically. This function exists primarily
// for testing.
func First() (*Device, error) {
	handle := C.libusb_open_device_with_vid_pid(context, idVendor, idProduct)
	if handle == nil {
		return nil, errors.New("no devices found")
	}
	if err := C.libusb_claim_interface(handle, interfaceNum); err != C.LIBUSB_SUCCESS {
		C.libusb_close(handle)
		return nil, &libusbError{err}
	}
	return &Device{
		dev:    C.libusb_get_device(handle),
		handle: handle,
	}, nil
}
示例#2
0
文件: usb.go 项目: giddyinc/gousb
// 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
	if err != nil {
		return nil, err
	}

	device := newDevice(handle, desc)
	return device, nil
}
示例#3
0
文件: usb.go 项目: hanwen/usb
// Get the underlying device for a handle.
func (h *DeviceHandle) Device() *Device {
	return (*Device)(C.libusb_get_device(h.me()))
}
示例#4
0
文件: usb.go 项目: thequux/gousb
// Return a *Device for the given handle.
func (h *DeviceHandle) GetDevice() *Device {
	return h.ctx.wrapDevice(C.libusb_get_device(h.handle))
}