Пример #1
0
static void tigl_get_product(char * string, size_t maxlen, struct libusb_device *dev)
{
	libusb_device_handle *han;
	int ret;
	struct libusb_device_descriptor desc;
	int r = libusb_get_device_descriptor(dev, &desc);

	string[0] = 0;

	if (r < 0)
	{
		ticables_critical("failed to get device descriptor");
	}

	if (desc.iProduct)
	{
		if (!libusb_open(dev, &han))
		{
			ret = libusb_get_string_descriptor_ascii(han, desc.iProduct, (unsigned char *) string, maxlen);
			libusb_close(han);
			if (ret <= 0)
			{
				ticables_warning("libusb_get_string_descriptor_ascii (%s).\n", tigl_strerror(ret));
			}
		}
		// else do nothing.
	}
}
Пример #2
0
static const char* tigl_get_product(struct libusb_device *dev)
{
    libusb_device_handle *han;
    int ret;
    static unsigned char string[64];

    struct libusb_device_descriptor desc;
    int r = libusb_get_device_descriptor(dev, &desc);
    if (r < 0)
    {
        ticables_error("failed to get device descriptor");
        return "";
    }

    if (desc.iProduct)
    {
        if (!libusb_open(dev, &han))
        {
            ret = libusb_get_string_descriptor_ascii(han, desc.iProduct, string, sizeof(string));
            libusb_close(han);
            if (ret > 0)
            {
                return (const char *) string;
            }
            else
            {
                ticables_warning("libusb_get_string_descriptor_ascii (%s).\n", tigl_strerror(ret));
                return "";
            }
        }
        else
        {
            return "";
        }
    }
    return (const char *)string;
}