Exemplo n.º 1
0
Arquivo: usb.go Projeto: thequux/gousb
func (handle *DeviceHandle) destroy() {
	if handle.handle != nil {
		C.libusb_close(handle.handle)
		handle.handle = nil
	}
	handle.ctx = nil
}
Exemplo n.º 2
0
func (dev *linuxDevice) Close() {
	if dev.handle != nil {
		C.libusb_close(dev.handle)
		dev.handle = nil
		dev.info = nil
	}
}
Exemplo n.º 3
0
// 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
}
Exemplo n.º 4
0
// 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
}
Exemplo n.º 5
0
// 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
}
Exemplo n.º 6
0
// 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
}
Exemplo n.º 7
0
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")

}
Exemplo n.º 8
0
Arquivo: usb.go Projeto: hanwen/usb
// Close a device handle.
func (h *DeviceHandle) Close() error {
	C.libusb_close(h.me())
	return nil
}
Exemplo n.º 9
0
// Close the device handle
func Close(handle *C.libusb_device_handle) {
	C.libusb_close(handle)
}