• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ USBDevice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了USBDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,代码来源:


示例16: catFile

void USBDevice::parseSysDir(int bus, int parent, int level, QString dname)
{
  _level = level;
  _parent = parent;
  _manufacturer = catFile(dname + "/manufacturer");
  _product = catFile(dname + "/product");

  _bus = bus;
  _device = catFile(dname + "/devnum").toUInt();

  if (_device == 1)
    _product += QString(" (%1)").arg(_bus);

  _vendorID = catFile(dname + "/idVendor").toUInt(0, 16);
  _prodID = catFile(dname + "/idProduct").toUInt(0, 16);

  _class = catFile(dname + "/bDeviceClass").toUInt(0, 16);
  _sub = catFile(dname + "/bDeviceSubClass").toUInt(0, 16);
  _maxPacketSize = catFile(dname + "/bMaxPacketSize0").toUInt();

  _speed = catFile(dname + "/speed").toDouble();
  _serial = catFile(dname + "/serial");
  _channels = catFile(dname + "/maxchild").toUInt();

  double version = catFile(dname + "/version").toDouble();
  _verMajor = int(version);
  _verMinor = int(10*(version - floor(version)));

  QDir dir(dname);
  dir.setNameFilter(QString("%1-*").arg(bus));
  dir.setFilter(QDir::Dirs);
  QStringList list = dir.entryList();

  for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
    if ((*it).contains(':'))
      continue;

    USBDevice* dev = new USBDevice();
    dev->parseSysDir(bus, ++level, _device, dname + "/" + *it);
  }
}
开发者ID:,项目名称:,代码行数:41,代码来源:


示例17: controller

bool USBDevice::parse(QString fname)
{
	static bool showErrorMessage = true;
	bool error = false;
	_devices.clear();
	
	QFile controller("/dev/usb0");
	int i = 1;
	while ( controller.exists() )
	{
		// If the devicenode exists, continue with further inspection
		if ( controller.open(IO_ReadOnly) )
		{
			for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) 
			{
				struct usb_device_info di;
				
				di.udi_addr = addr;
				if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 )
				{
					if (!find( di.udi_bus, di.udi_addr ) )
					{
						USBDevice *device = new USBDevice();
						device->collectData( controller.handle(), 0, di, 0);
					}
				}
			}
			controller.close();
		} else {
			error = true;
		}
		controller.setName( QString::fromLocal8Bit("/dev/usb%1").arg(i++) );
	}
	
	if ( showErrorMessage && error ) {
		showErrorMessage = false;
		KMessageBox::error( 0, i18n("Could not open one or more USB controller. Make sure, you have read access to all USB controllers that should be listed here."));
	}
	
	return true;
}
开发者ID:,项目名称:,代码行数:41,代码来源:


示例18: switch

//!!Polymorphism would be easier to implement!
BOOL USBDeviceHandle::Open(const USBDevice& clDevice_, USBDeviceHandle*& pclDeviceHandle_, ULONG ulBaudRate_)
{
   //dynamic_cast does not handle *& types

   BOOL bSuccess;
   switch(clDevice_.GetDeviceType())
   {
      case DeviceType::SI_LABS:
      {
         const USBDeviceSI& clDeviceSi = dynamic_cast<const USBDeviceSI&>(clDevice_);
         
         USBDeviceHandleSI* pclDeviceHandleSi;
         bSuccess = USBDeviceHandleSI::Open(clDeviceSi, pclDeviceHandleSi, ulBaudRate_);
         
         //pclDeviceHandle_ = dynamic_cast<USBDeviceHandle*>(pclDeviceHandleSi);
         pclDeviceHandle_ = pclDeviceHandleSi;
         break;
      }

      case DeviceType::SI_LABS_IOKIT:
      {
         const USBDeviceIOKit& clDeviceSi = dynamic_cast<const USBDeviceIOKit&>(clDevice_);
         
         USBDeviceHandleSIIOKit* pclDeviceHandleSiIOKit;
         bSuccess = USBDeviceHandleSIIOKit::Open(clDeviceSi, pclDeviceHandleSiIOKit, ulBaudRate_);
         
         //pclDeviceHandle_ = dynamic_cast<USBDeviceHandle*>(pclDeviceHandleSiIOKit);
         pclDeviceHandle_ = pclDeviceHandleSiIOKit;
         break;
      }
      
      case DeviceType::IO_KIT:
      {
         const USBDeviceIOKit& clDeviceIOKit = dynamic_cast<const USBDeviceIOKit&>(clDevice_);
         
         USBDeviceHandleIOKit* pclDeviceHandleIOKit;
         bSuccess = USBDeviceHandleIOKit::Open(clDeviceIOKit, pclDeviceHandleIOKit);
         
         //pclDeviceHandle_ = dynamic_cast<USBDeviceHandle*>(pclDeviceHandleIOKit);
         pclDeviceHandle_ = pclDeviceHandleIOKit;
         break;
      }
      
      default:
      {
         pclDeviceHandle_ = NULL;
         bSuccess = FALSE;
         break;
      }
   }

   return bSuccess;
}
开发者ID:corbamico,项目名称:ANT-Library,代码行数:54,代码来源:usb_device_handle_mac.cpp


示例19: Java_com_stericsson_sdk_equipment_io_usb_internal_USBNativeDevice_close

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

		if (device) {
			device->close(env);
			Logger::getInstance()->debug(LP, "Removing device from internal cache..");
			usbHandler->removeDevice(device->getKey());
			if (usbHandler->getDevice(device->getKey()) != NULL) {
				Logger::getInstance()->error(LP, "Removing from internal cache failed!");
			}
		} 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 close!");
	}
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:22,代码来源:libusb_jni.cpp


示例20: GetUSBDeviceList

// this is the diary of a mad man
bool GetUSBDeviceList(vector<USBDevice> &pDevList)
{
	FlushDirCache();

	std::map< CString, vector<CString> > sDevInterfaceList;
	vector<CString> sDirList;
	GetDirListing( "/rootfs/sys/bus/usb/devices/", sDirList, true, false );
	for (unsigned i = 0; i < sDirList.size(); i++)
	{
		CString sDirEntry = sDirList[i];
		vector<CString> components;

		if (sDirEntry.substr(0, 3) == "usb") continue;

		split( sDirEntry, ":", components, true );
		if ( components.size() < 2 ) continue;

		if ( ! IsADirectory( "/rootfs/sys/bus/usb/devices/" + components[0] ) ) continue;

		// I win --infamouspat
		sDevInterfaceList[components[0]].push_back(components[1]);

	}

	map< CString, vector<CString> >::iterator iter;
 
	for(iter = sDevInterfaceList.begin(); iter != sDevInterfaceList.end(); iter++)
	{
		USBDevice newDev;
		CString sDevName = iter->first;
		vector<CString> sDevChildren = iter->second;
		
		if ( newDev.Load(sDevName, sDevChildren) )
			pDevList.push_back(newDev);
	}

	return true;
}
开发者ID:BitMax,项目名称:openitg,代码行数:39,代码来源:USBDevice.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ USBDevice_SAMD21G18x类代码示例发布时间:2022-05-31
下一篇:
C++ USARTClass类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap