Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在为Mac编写一个Foundation工具,并尝试检测Apple设备何时通过USB连接和断开连接.我在 this post和 USBPrivateDataSample中找到了一些帮助 – 但是如果我同时提供供应商ID和产品ID,它似乎只能起作用.我想消除产品ID并找到Apple设备上的所有USB事件(供应商ID 1452).有什么帮助吗? 这是我的代码似乎没有检测到任何设备: #include 我正在为Mac编写一个Foundation工具,并尝试检测Apple设备何时通过USB连接和断开连接.我在 this post和 USBPrivateDataSample中找到了一些帮助 – 但是如果我同时提供供应商ID和产品ID,它似乎只能起作用.我想消除产品ID并找到Apple设备上的所有USB事件(供应商ID 1452).有什么帮助吗?

这是我的代码似乎没有检测到任何设备:

#include <CoreFoundation/CoreFoundation.h>#include <IOKit/IOKitlib.h>#include <IOKit/IOMessage.h>#include <IOKit/IOCFPlugIn.h>#include <IOKit/usb/IoUSBlib.h>#define kMyvendorID 1452int List_devices(voID);int List_devices(voID){    cfmutabledictionaryRef matchingDict;    io_iterator_t iter;    kern_return_t kr;    io_service_t device;    CFNumberRef numberRef;    long usbvendor = kMyvendorID;    /* set up a matching dictionary for the class */    matchingDict = IOServiceMatching(kIoUSBDeviceClassname);    // Interested in instances of class    // IoUSBDevice and its subclasses    if (matchingDict == NulL) {        fprintf(stderr,"IOServiceMatching returned NulL.\n");        return -1;    }    // We are interested in all USB devices (as opposed to USB interfaces).  The Common Class Specification    // tells us that we need to specify the IDvendor,IDProduct,and bcdDevice fIElds,or,if we're not interested    // in particular bcdDevices,just the IDvendor and IDProduct.  Note that if we were trying to match an     // IoUSBInterface,we would need to set more values in the matching dictionary (e.g. IDvendor,// bInterfaceNumber and bConfigurationValue.    // Create a CFNumber for the IDvendor and set the value in the dictionary    numberRef = CFNumberCreate(kcfAllocatorDefault,kcfNumberSInt32Type,&usbvendor);    CFDictionarySetValue(matchingDict,CFSTR(kUSBvendorID),numberRef);    CFRelease(numberRef);    numberRef = NulL;        /* Now we have a dictionary,get an iterator.*/    kr = IOServiceGetMatchingServices(kIOMasterPortDefault,matchingDict,&iter);    if (kr != KERN_SUCCESS)        return -1;    /* iterate */    while ((device = IOIteratorNext(iter)))    {        io_name_t       devicename;        CFStringRef     devicenameAsCFString;           /* do something with device,eg. check propertIEs */        /* ... */        /* And free the reference taken before continuing to the next item */        // Get the USB device's name.        kr = IORegistryEntryGetname(device,devicename);        if (KERN_SUCCESS != kr) {            devicename[0] = '
long vID = 1452; //Apple vendor ID        CFNumberRef refvendorID = CFNumberCreate (kcfAllocatorDefault,kcfNumberIntType,&vID);        CFDictionarySetValue (matchingDict,CFSTR ("IDvendor"),refvendorID);        CFRelease(refvendorID);        //all product by same vendor        CFDictionarySetValue (matchingDict,CFSTR ("IDProduct"),CFSTR("*"));
'; } devicenameAsCFString = CFStringCreateWithCString(kcfAllocatorDefault,devicename,kcfStringEnCodingASCII); // Dump our data to stderr just to see what it looks like. fprintf(stderr,"devicename: "); CFShow(devicenameAsCFString); IOObjectRelease(device); } /* Done,release the iterator */ IOObjectRelease(iter); return 1;}int main(int argc,char* argv[]){ while(1){ List_devices(); sleep(1); } return 0;}

值得注意的是:如果我将一个产品ID添加到matchingDict并插入这样的设备,它将发现设备没有问题(不更改供应商ID).但我无法单独使用供应商ID找到它.

解决方法 要获取属于特定供应商的所有产品的列表,您可以在产品ID字段中使用通配符.示例匹配条件如下:

[+++] 总结

以上是内存溢出为你收集整理的macos – Cocoa:按供应商ID检测USB设备全部内容,希望文章能够帮你解决macos – Cocoa:按供应商ID检测USB设备所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
macos – Cocoa:按供应商ID检测USB设备_app_内存溢出

macos – Cocoa:按供应商ID检测USB设备

macos – Cocoa:按供应商ID检测USB设备,第1张

概述我正在为Mac编写一个Foundation工具,并尝试检测Apple设备何时通过USB连接和断开连接.我在 this post和 USBPrivateDataSample中找到了一些帮助 – 但是如果我同时提供供应商ID和产品ID,它似乎只能起作用.我想消除产品ID并找到Apple设备上的所有USB事件(供应商ID 1452).有什么帮助吗? 这是我的代码似乎没有检测到任何设备: #include 我正在为Mac编写一个Foundation工具,并尝试检测Apple设备何时通过USB连接和断开连接.我在 this post和 USBPrivateDataSample中找到了一些帮助 – 但是如果我同时提供供应商ID和产品ID,它似乎只能起作用.我想消除产品ID并找到Apple设备上的所有USB事件(供应商ID 1452).有什么帮助吗?

这是我的代码似乎没有检测到任何设备:

#include <CoreFoundation/CoreFoundation.h>#include <IOKit/IOKitlib.h>#include <IOKit/IOMessage.h>#include <IOKit/IOCFPlugIn.h>#include <IOKit/usb/IoUSBlib.h>#define kMyvendorID 1452int List_devices(voID);int List_devices(voID){    cfmutabledictionaryRef matchingDict;    io_iterator_t iter;    kern_return_t kr;    io_service_t device;    CFNumberRef numberRef;    long usbvendor = kMyvendorID;    /* set up a matching dictionary for the class */    matchingDict = IOServiceMatching(kIoUSBDeviceClassname);    // Interested in instances of class    // IoUSBDevice and its subclasses    if (matchingDict == NulL) {        fprintf(stderr,"IOServiceMatching returned NulL.\n");        return -1;    }    // We are interested in all USB devices (as opposed to USB interfaces).  The Common Class Specification    // tells us that we need to specify the IDvendor,IDProduct,and bcdDevice fIElds,or,if we're not interested    // in particular bcdDevices,just the IDvendor and IDProduct.  Note that if we were trying to match an     // IoUSBInterface,we would need to set more values in the matching dictionary (e.g. IDvendor,// bInterfaceNumber and bConfigurationValue.    // Create a CFNumber for the IDvendor and set the value in the dictionary    numberRef = CFNumberCreate(kcfAllocatorDefault,kcfNumberSInt32Type,&usbvendor);    CFDictionarySetValue(matchingDict,CFSTR(kUSBvendorID),numberRef);    CFRelease(numberRef);    numberRef = NulL;        /* Now we have a dictionary,get an iterator.*/    kr = IOServiceGetMatchingServices(kIOMasterPortDefault,matchingDict,&iter);    if (kr != KERN_SUCCESS)        return -1;    /* iterate */    while ((device = IOIteratorNext(iter)))    {        io_name_t       devicename;        CFStringRef     devicenameAsCFString;           /* do something with device,eg. check propertIEs */        /* ... */        /* And free the reference taken before continuing to the next item */        // Get the USB device's name.        kr = IORegistryEntryGetname(device,devicename);        if (KERN_SUCCESS != kr) {            devicename[0] = '
long vID = 1452; //Apple vendor ID        CFNumberRef refvendorID = CFNumberCreate (kcfAllocatorDefault,kcfNumberIntType,&vID);        CFDictionarySetValue (matchingDict,CFSTR ("IDvendor"),refvendorID);        CFRelease(refvendorID);        //all product by same vendor        CFDictionarySetValue (matchingDict,CFSTR ("IDProduct"),CFSTR("*"));
'; } devicenameAsCFString = CFStringCreateWithCString(kcfAllocatorDefault,devicename,kcfStringEnCodingASCII); // Dump our data to stderr just to see what it looks like. fprintf(stderr,"devicename: "); CFShow(devicenameAsCFString); IOObjectRelease(device); } /* Done,release the iterator */ IOObjectRelease(iter); return 1;}int main(int argc,char* argv[]){ while(1){ List_devices(); sleep(1); } return 0;}

值得注意的是:如果我将一个产品ID添加到matchingDict并插入这样的设备,它将发现设备没有问题(不更改供应商ID).但我无法单独使用供应商ID找到它.

解决方法 要获取属于特定供应商的所有产品的列表,您可以在产品ID字段中使用通配符.示例匹配条件如下:

总结

以上是内存溢出为你收集整理的macos – Cocoa:按供应商ID检测USB设备全部内容,希望文章能够帮你解决macos – Cocoa:按供应商ID检测USB设备所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1020432.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存