Created
November 21, 2012 10:50
-
-
Save rhwood/4124251 to your computer and use it in GitHub Desktop.
ORSSerialPortManager:shouldAddSerialPort: sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)serialPortManager:(ORSSerialPortManager *)manager shouldAddSerialPort:(ORSSerialPort *)serialPort { | |
CFMutableDictionaryRef usbProperties = 0; | |
io_object_t device = 0; | |
io_iterator_t iterator = 0; | |
BOOL add = NO; | |
if (KERN_SUCCESS == IORegistryEntryCreateIterator(serialPort.device, kIOServicePlane, kIORegistryIterateRecursively + kIORegistryIterateParents, &iterator)) { | |
while ((device = IOIteratorNext(iterator))) { | |
if (KERN_SUCCESS == IORegistryEntryCreateCFProperties(device, &usbProperties, kCFAllocatorDefault, kNilOptions)) { | |
NSUInteger vendorId = 0, productId = 0; | |
CFTypeRef reference; | |
reference = CFDictionaryGetValue(usbProperties, CFSTR(kUSBVendorID)); | |
if (reference) { | |
CFNumberGetValue(reference, kCFNumberIntType, &vendorId); | |
} | |
reference = CFDictionaryGetValue(usbProperties, CFSTR(kUSBProductID)); | |
if (reference) { | |
CFNumberGetValue(reference, kCFNumberIntType, &productId); | |
} | |
if (vendorId && productId) { // we have a USB device | |
add = (vendorId == 0x4d8 && product == 0xff7e); | |
IOObjectRelease(device); // release because we skip the normal release in the loop | |
break; | |
} | |
} | |
IOObjectRelease(device); // release device before next iteration | |
} | |
} | |
IOObjectRelease(iterator); | |
return add; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment