Hello,
I am learning how to develop a USB driver. The code below is how far I get before running into errors. The error being "plugin failed e00002c7".
I am also not sure what "score" does or means.
From what I read in the sample codes, documentation and the net, my guess is that I can't get exclusive access to any of the USB devices I have.
Apple is great, it works with many different USB devices right out of the box. But it sure sucks when you try to learn driver development yourself.
Any ideas on how I can get exclusieve access to a device? Or do you know a cheap USB-device that Mac OS X doesn't know?
I am learning how to develop a USB driver. The code below is how far I get before running into errors. The error being "plugin failed e00002c7".
I am also not sure what "score" does or means.
From what I read in the sample codes, documentation and the net, my guess is that I can't get exclusive access to any of the USB devices I have.
Apple is great, it works with many different USB devices right out of the box. But it sure sucks when you try to learn driver development yourself.
Any ideas on how I can get exclusieve access to a device? Or do you know a cheap USB-device that Mac OS X doesn't know?
Code:
kern_return_t err; //error
//get comm port
mach_port_t masterPort = 0; //requires mach.h
err = IOMasterPort(MACH_PORT_NULL, &masterPort); //get comm port
//build matching dictionary
CFMutableDictionaryRef matchingDictionary = 0; // requires <IOKit/IOKitLib.h>
matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName); //USB class devices
[self printDic:matchingDictionary];
io_iterator_t iterator = 0;
IOServiceGetMatchingServices(masterPort,matchingDictionary,&iterator); //matchingDictionary retaincount--
io_service_t usbDeviceRef;
int i=0;
while (usbDeviceRef = IOIteratorNext(iterator)) {i++;
io_connect_t dataPort;
err = IOServiceOpen(usbDeviceRef, mach_task_self(), 0, &dataPort);//open connection
printf("Found device %i: %p - %p - ",i, (void*)usbDeviceRef, (void*)dataPort);
//characteristics
io_name_t myclass;
IOObjectGetClass(usbDeviceRef,myclass);
printf("class: %s - ",myclass);
io_name_t devName;
IORegistryEntryGetName(usbDeviceRef,devName);
printf("name: %s - ", devName);
SInt32 score;
IOCFPlugInInterface **iodev; // requires <IOKit/IOCFPlugIn.h>
err = IOCreatePlugInInterfaceForService(usbDeviceRef, kIOUSBDeviceInterfaceID182, kIOCFPlugInInterfaceID, &iodev, &score);
if (err){
printf("plugin failed %08x \n",err);
} else {printf("plugin ok \n");}
IOObjectRelease(usbDeviceRef); // no longer need this reference
IOServiceClose(dataPort);//close connection
}
IOObjectRelease(iterator);