Building on the project in part 1, weíre going to
expand our project to extract the deviceís Model and Serial Number!
Once again, Iíll be using an ONTRAK ADU208 as my test device, but
similar steps should work with other USB HID devices too.
In part 1, we created a function that gets called every time a matching
device is connected to the system. At present, this function simply logs
the device ID to the console. Letís modify that function to store the
Name and Serial Number, then log them to the console:
// New USB device
specified in the matching dictionary has been added (callback function)
// Retrieve the device name & serial number
*devName = [NSString stringWithUTF8String:
*devSerialNumber = [NSString
// Log the device reference, Name, Serial
Number & device count
device added: %p\nModel: %@\nSerial Number:%@\nONTRAK device count:
Youíll note that Iím using the IOHIDDeviceGetProperty
function to retrieve both the Model and the Serial
Number. IOHIDDeviceGetProperty returns a pointer to a
CFTypeRef, which is not necessarily a string. Since Iím
woking with an ONTRAK Control Systems ADU device, I knew
the type returned would be a string. In a production
application, it would be prudent to verify the type
returned before assigning it to a string.
At this point you can go ahead and run your project - it
will now log the device Reference, Model and Serial
Number when attached to your system!
Download the Xcode 4 project file
This project was created on OS X 10.7.3 using Xcode
Next time we will write to the device to open & close
next step.....Simple Read/Write For Ontrak
USB Data Acquisition Interfaces ( XCODE )
Back to Programming Page