Example #1
0
// GetDeviceUsbStrings Gets USB device strings for manufacturer name, product
// name, and serial number if they are available.
func GetDeviceUsbStrings(index int) (string, string, string, error) {
	var manufacturer *C.char
	manufacturer = (*C.char)(C.calloc(1, 256))
	defer C.free(unsafe.Pointer(manufacturer))

	var product *C.char
	product = (*C.char)(C.calloc(1, 256))
	defer C.free(unsafe.Pointer(product))

	var serial *C.char
	serial = (*C.char)(C.calloc(1, 256))
	defer C.free(unsafe.Pointer(serial))

	// Returns 0 on success
	retval := C.rtlsdr_get_device_usb_strings(
		C.uint32_t(index),
		manufacturer,
		product,
		serial)

	if retval != 0 {
		return "", "", "", fmt.Errorf("GetDeviceUsbStrings returned error value: %d", retval)
	}

	return C.GoString(manufacturer), C.GoString(product), C.GoString(serial), nil
}
Example #2
0
// Get USB device strings.
//
// int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact, char *product, char *serial);
// rtlsdr_get_device_usb_strings returns 0 on success
func GetDeviceUsbStrings(index int) (manufact, product, serial string, err int) {
	m := make([]byte, 257) // includes space for NULL byte
	p := make([]byte, 257)
	s := make([]byte, 257)
	err = int(C.rtlsdr_get_device_usb_strings(C.uint32_t(index),
		(*C.char)(unsafe.Pointer(&m[0])),
		(*C.char)(unsafe.Pointer(&p[0])),
		(*C.char)(unsafe.Pointer(&s[0]))))
	return string(m), string(p), string(s), err
}
Example #3
0
// GetDeviceUsbStrings returns the information of a device by index.
func GetDeviceUsbStrings(index int) (manufact, product, serial string, err error) {
	m := make([]byte, 257) // includes space for NULL byte
	p := make([]byte, 257)
	s := make([]byte, 257)
	i := int(C.rtlsdr_get_device_usb_strings(C.uint32_t(index),
		(*C.char)(unsafe.Pointer(&m[0])),
		(*C.char)(unsafe.Pointer(&p[0])),
		(*C.char)(unsafe.Pointer(&s[0]))))
	return string(bytes.Trim(m, "\x00")), string(bytes.Trim(p, "\x00")),
		string(bytes.Trim(s, "\x00")), libError(i)
}