当前位置: 首页>>代码示例>>C++>>正文


C++ USBDevice类代码示例

本文整理汇总了C++中USBDevice的典型用法代码示例。如果您正苦于以下问题:C++ USBDevice类的具体用法?C++ USBDevice怎么用?C++ USBDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了USBDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: jsonDeviceMessage

void FCServer::jsonDeviceMessage(rapidjson::Document &message)
{
    /*
     * If this message has a "device" member and doesn't match any server-global
     * message types, give each matching device a chance to handle it.
     */

    const Value &device = message["device"];
    bool matched = false;

    if (device.IsObject()) {
        for (unsigned i = 0; i != mUSBDevices.size(); i++) {
            USBDevice *usbDev = mUSBDevices[i];

            if (usbDev->matchConfiguration(device)) {
                matched = true;
                usbDev->writeMessage(message);
                if (message.HasMember("error"))
                    break;
            }
        }
    }

    if (!matched) {
        message.AddMember("error", "No matching device found", message.GetAllocator());
    }
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:27,代码来源:fcserver.cpp

示例2: Java_com_stericsson_sdk_equipment_io_usb_internal_USBNativeDevice_write

JNIEXPORT jint JNICALL Java_com_stericsson_sdk_equipment_io_usb_internal_USBNativeDevice_write(
		JNIEnv *env, jobject src, jbyteArray data, jint offset, jint length,
		jint timeout) {
	try {
		USBDevice *device = getUSBDevice(env, src);

		if (device) {
			jsize dataLength = env->GetArrayLength(data);
			if ((offset < 0) || ((offset + length) > dataLength)) {
				std::stringstream ss;
				ss<<"offset:"<<offset<<"\tlength: "<<length<<"\tdataLength: "<<dataLength;
				Logger::getInstance()->error(LP, ss.str());
				env->ThrowNew(env->FindClass(EX_ARRAY_INDEX_OUT_OF_BOUND),
						"Given offset and length exceeds write buffer space!");
			} else {
				jbyte *buf = (jbyte *) malloc(length * sizeof(jbyte));
				env->GetByteArrayRegion(data, offset, length, buf);

				int ret = device->bulkWrite(env, (char *) buf, length, timeout);
				free(buf);
				return ret;
			}
		} else {
			Logger::getInstance()->error(LP, "Cannot find device!");
		}
	} catch (const char *errorString) {
		env->ThrowNew(env->FindClass(EX_NATIVE_EXCEPTION), errorString);
	} catch (...) {
		env->ThrowNew(env->FindClass(EX_NATIVE_EXCEPTION),
				"Unexpected native call failure in method write!");
	}

	return UNDEF;
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:34,代码来源:libusb_jni.cpp

示例3: libusb_handle_events_timeout_completed

void FCServer::mainLoop()
{
    for (;;) {
        struct timeval timeout;
        timeout.tv_sec = 0;
        timeout.tv_usec = 100000;

        int err = libusb_handle_events_timeout_completed(mUSB, &timeout, 0);
        if (err) {
            std::clog << "Error handling USB events: " << libusb_strerror(libusb_error(err)) << "\n";
            // Sometimes this happens on Windows during normal operation if we're queueing a lot of output URBs. Meh.
        }

        // We may have been asked for a one-shot poll, to retry connecting devices that failed.
        if (mPollForDevicesOnce) {
            mPollForDevicesOnce = false;
            usbHotplugPoll();
        }

        // Flush completed transfers
        mEventMutex.lock();
        for (std::vector<USBDevice*>::iterator i = mUSBDevices.begin(), e = mUSBDevices.end(); i != e; ++i) {
            USBDevice *dev = *i;
            dev->flush();
        }
        mEventMutex.unlock();
    }
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:28,代码来源:fcserver.cpp

示例4: switch

void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent)
{
	// determine data for this device
	_level        = level;
	_parent       = parent;
	
	_bus          = di.udi_bus;
	_device       = di.udi_addr;
	_product      = QString::fromLatin1(di.udi_product);
	if ( _device == 1 )
		_product += " " + QString::number( _bus );
	_manufacturer = QString::fromLatin1(di.udi_vendor);
	_prodID       = di.udi_productNo;
	_vendorID     = di.udi_vendorNo;
	_class        = di.udi_class;
	_sub          = di.udi_subclass;
	_prot         = di.udi_protocol;
	_power        = di.udi_power;
	_channels     = di.udi_nports;
	
	// determine the speed
#if __FreeBSD_version > 490102
	switch (di.udi_speed) {
		case USB_SPEED_LOW:  _speed = 1.5;   break;
		case USB_SPEED_FULL: _speed = 12.0;  break;
		case USB_SPEED_HIGH: _speed = 480.0; break;
	}
#else
	_speed = di.udi_lowspeed ? 1.5 : 12.0;
#endif

	// Get all attached devicenodes
	for ( int i = 0; i < USB_MAX_DEVNAMES; ++i )
		if ( di.udi_devnames[i][0] )
			_devnodes << di.udi_devnames[i];

	// For compatibility, split the revision number
	sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor );

	// Cycle through the attached devices if there are any
	for ( int p = 0; p < di.udi_nports; ++p ) {
		// Get data for device
		struct usb_device_info di2;

		di2.udi_addr = di.udi_ports[p];
		
		if ( di2.udi_addr >= USB_MAX_DEVICES )
			continue;
			
		if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 )
			continue;

		// Only add the device if we didn't detect it, yet
		if (!find( di2.udi_bus, di2.udi_addr ) )
		{
			USBDevice *device = new USBDevice();
			device->collectData( fd, level + 1, di2, di.udi_addr );
		}
	}
}
开发者ID:,项目名称:,代码行数:60,代码来源:

示例5: haiku_get_device_descriptor

static int 
haiku_get_device_descriptor(struct libusb_device *device, unsigned char* buffer, int *host_endian)
{
	USBDevice *dev = *((USBDevice**)(device->os_priv));
	memcpy(buffer,dev->Descriptor(),DEVICE_DESC_LENGTH);
	*host_endian=0;
	return LIBUSB_SUCCESS; 
}
开发者ID:Abzol,项目名称:CorsairRGBScript,代码行数:8,代码来源:haiku_usb_raw.cpp

示例6: inCallback

LIBUSB_CALL void inCallback(libusb_transfer* transfer)
{
    // don't call the device as it might already have been destroyed
    if (transfer->status != LIBUSB_TRANSFER_CANCELLED) {
        USBDevice *device = reinterpret_cast<USBDevice*>(transfer->user_data);
        device->inCallback(transfer);
    }
    libusb_free_transfer(transfer);
}
开发者ID:MrKarimiD,项目名称:framework,代码行数:9,代码来源:usbdevice.cpp

示例7: usbDeviceLeft

void FCServer::usbDeviceLeft(std::vector<USBDevice*>::iterator iter)
{
    USBDevice *dev = *iter;
    if (mVerbose) {
        std::clog << "USB device " << dev->getName() << " removed.\n";
    }
    mUSBDevices.erase(iter);
    delete dev;
    jsonConnectedDevicesChanged();
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:10,代码来源:fcserver.cpp

示例8: haiku_get_active_config_descriptor

static int
haiku_get_active_config_descriptor(struct libusb_device *device, unsigned char *buffer, size_t len, int *host_endian)
{
	USBDevice *dev = *((USBDevice**)(device->os_priv));
	const usb_configuration_descriptor* act_config = dev->ActiveConfiguration();
	if(len>act_config->total_length)
	{
		return LIBUSB_ERROR_OVERFLOW;
	}
	memcpy(buffer,act_config,len);
	*host_endian=0;
	return LIBUSB_SUCCESS;
}
开发者ID:Abzol,项目名称:CorsairRGBScript,代码行数:13,代码来源:haiku_usb_raw.cpp

示例9: USBInterface

// _________________________________________________________________________________________
//	USBInterfaceManager::ServicePublished
//
void	USBInterfaceManager::ServicePublished(io_service_t ioInterfaceObj)
{
	USBInterface *interface = new USBInterface(NULL, ioInterfaceObj);
	USBDevice *device = interface->GetDevice();
	
	if (device != NULL && device->Usable() && interface->Usable()) {
		// Ask subclass if it's a device we want to work with
		if (MatchInterface(interface)) {
			OSStatus err = UseInterface(interface);
			if (err == noErr)
				return;	// ownership of interface is passed off
			// how to report error???
		}
	}
	delete interface;
}
开发者ID:fruitsamples,项目名称:MIDI,代码行数:19,代码来源:USBInterfaceManager.cpp

示例10: cbOpcMessage

void FCServer::cbOpcMessage(OPC::Message &msg, void *context)
{
    /*
     * Broadcast the OPC message to all configured devices.
     */

    FCServer *self = static_cast<FCServer*>(context);
    self->mEventMutex.lock();

    for (std::vector<USBDevice*>::iterator i = self->mUSBDevices.begin(), e = self->mUSBDevices.end(); i != e; ++i) {
        USBDevice *dev = *i;
        dev->writeMessage(msg);
    }

    self->mEventMutex.unlock();
}
开发者ID:Elfkay,项目名称:fadecandy,代码行数:16,代码来源:fcserver.cpp

示例11: haiku_get_config_descriptor

static int
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
	USBDevice *dev = *((USBDevice**)(device->os_priv));
	const usb_configuration_descriptor* config = dev->ConfigurationDescriptor(config_index);
	if(config==NULL)
	{
		usbi_err(DEVICE_CTX(device),"failed getting configuration descriptor");
		return LIBUSB_ERROR_INVALID_PARAM;
	}
	if(len>config->total_length)
		len=config->total_length;
	memcpy(buffer,(unsigned char*)config,len);
	*host_endian=0;
	return len;
}
开发者ID:Abzol,项目名称:CorsairRGBScript,代码行数:16,代码来源:haiku_usb_raw.cpp

示例12: USBDevice

// _________________________________________________________________________________________
//	USBDeviceManager::ServicePublished
//
void	USBDeviceManager::ServicePublished(io_service_t ioDeviceObj)
{
	USBDevice *device = new USBDevice(ioDeviceObj);
	if (device->Usable()) {
		// Ask subclass if it's a device we want to work with
		if (MatchDevice(device)) {
			// hardcoded to use configuration 0 for now
			if (device->OpenAndConfigure(0)) {
				OSStatus err = UseDevice(device);
				if (err == noErr)
					return;	// ownership of device is passed off
				// how to report error???
			}
		}
	}
	delete device;
}
开发者ID:JoeMatt,项目名称:aurora-mixer-drivers,代码行数:20,代码来源:USBDeviceManager.cpp

示例13: Java_com_stericsson_sdk_equipment_io_usb_internal_USBNativeDevice_open

JNIEXPORT void JNICALL Java_com_stericsson_sdk_equipment_io_usb_internal_USBNativeDevice_open(
		JNIEnv *env, jobject src) {
	try {
		USBDevice *device = getUSBDevice(env, src);

		if (device) {
			device->open();
		} else {
			Logger::getInstance()->error(LP, "Cannot find device!");
		}
	} catch (const char *errorString) {
		env->ThrowNew(env->FindClass(EX_NATIVE_EXCEPTION), errorString);
	} catch (...) {
		env->ThrowNew(env->FindClass(EX_NATIVE_EXCEPTION),
				"Unexpected native call failure in method open!");
	}
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:17,代码来源:libusb_jni.cpp

示例14: while

bool USBDevice::parse(QString fname)
{
  _devices.clear();

  QString result;

  // read in the complete file
  //
  // Note: we can't use a QTextStream, as the files in /proc
  // are pseudo files with zero length
  char buffer[256];
  int fd = ::open(QFile::encodeName(fname), O_RDONLY);
  if (fd<0)
	return false;

  if (fd >= 0)
    {
      ssize_t count;
      while ((count = ::read(fd, buffer, 256)) > 0)
	result.append(QString(buffer).left(count));

      ::close(fd);
    }

  // read in the device infos
  USBDevice *device = 0;
  int start=0, end;
  result.replace(QRegExp("^\n"),"");
  while ((end = result.find('\n', start)) > 0)
    {
      QString line = result.mid(start, end-start);

      if (line.startsWith("T:"))
	device = new USBDevice();

      if (device)
	device->parseLine(line);

      start = end+1;
    }
  return true;
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例15: d

bool USBDevice::parseSys(QString dname)
{
   QDir d(dname);
   d.setNameFilter("usb*");
   QStringList list = d.entryList();

   for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
     USBDevice* device = new USBDevice();

     int bus = 0;
     QRegExp bus_reg("[a-z]*([0-9]+)");
     if (bus_reg.search(*it) != -1)
         bus = bus_reg.cap(1).toInt();


     device->parseSysDir(bus, 0, 0, d.absPath() + "/" + *it);
  }

  return d.count();
}
开发者ID:,项目名称:,代码行数:20,代码来源:


注:本文中的USBDevice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。