示例#1
0
文件: usb.go 项目: thequux/gousb
func (handle *DeviceHandle) destroy() {
	if handle.handle != nil {
		C.libusb_close(handle.handle)
		handle.handle = nil
	}
	handle.ctx = nil
}
示例#2
0
文件: hid_linux.go 项目: tam7t/hid
func (dev *linuxDevice) Close() {
	if dev.handle != nil {
		C.libusb_close(dev.handle)
		dev.handle = nil
		dev.info = nil
	}
}
示例#3
0
文件: eeprom.go 项目: sstallion/go
// Close releases the interface and closes the device. A device may not be
// opened again after calling this method. Returned errors may be safely
// ignored.
func (d *Device) Close() error {
	defer C.libusb_close(d.handle)

	if err := C.libusb_release_interface(d.handle, interfaceNum); err != C.LIBUSB_SUCCESS {
		return &libusbError{err}
	}
	return nil
}
示例#4
0
文件: eeprom.go 项目: sstallion/go
// Open opens an attached device and claims the interface. To ensure proper
// reference counting, Open must be called within the context of a Walk.
func (d *Device) Open() error {
	if err := C.libusb_open(d.dev, &d.handle); err != C.LIBUSB_SUCCESS {
		return &libusbError{err}
	}
	if err := C.libusb_claim_interface(d.handle, interfaceNum); err != C.LIBUSB_SUCCESS {
		C.libusb_close(d.handle)
		return &libusbError{err}
	}
	return nil
}
示例#5
0
文件: device.go 项目: giddyinc/gousb
// Close the device.
func (d *Device) Close() error {
	if d.handle == nil {
		return fmt.Errorf("usb: double close on device")
	}
	d.lock.Lock()
	defer d.lock.Unlock()
	for iface := range d.claimed {
		C.libusb_release_interface(d.handle, C.int(iface))
	}
	C.libusb_close(d.handle)
	d.handle = nil
	return nil
}
示例#6
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
}
示例#7
0
文件: hid_linux.go 项目: tam7t/hid
func resolveDescriptors(dev *C.libusb_device, iManufacturer C.uint8_t, iProduct C.uint8_t) (manufacturer string, product string, e error) {
	var handle *C.libusb_device_handle
	err := C.libusb_open(dev, &handle)
	if err != 0 {
		return "", "", usbError(err)
	}
	if handle != nil {
		defer C.libusb_close(handle)
		manufacturerStr, err := getStringDescriptor(handle, iManufacturer)
		if err != nil {
			return "", "", err
		}
		productStr, err := getStringDescriptor(handle, iProduct)
		if err != nil {
			return "", "", err
		}
		return manufacturerStr, productStr, nil
	}
	return "", "", errors.New("Couldn't resolve description string")

}
示例#8
0
文件: usb.go 项目: hanwen/usb
// Close a device handle.
func (h *DeviceHandle) Close() error {
	C.libusb_close(h.me())
	return nil
}
示例#9
0
// Close the device handle
func Close(handle *C.libusb_device_handle) {
	C.libusb_close(handle)
}