Re: Locating a USB device
Re: Locating a USB device
- Subject: Re: Locating a USB device
- From: Tomas Zahradnicky <email@hidden>
- Date: Sun, 19 Jan 2003 23:35:28 +0100
I have some code using Andraes Meyer's serial port code (thanks!). I
need to locate a cell phone attached to a USB port. I came up with
the following code:
a1 = [sPortList getPortList];
for (i=0;i<[a1 count];i++) {
if ([[[a1 objectAtIndex:i] bsdPath] hasPrefix:@"/dev/cu.usbmodem"]) {
[thePort setString:[[a1 objectAtIndex:i] bsdPath]];
NSLog(@"Found %@",[[a1 objectAtIndex:i] bsdPath]);
}
}
Which seems to work fine. The bsdPath is different depending on the
USB port you connect to, but they always seem to be prefixed with
cu.usbmodem and are then suffixed with a number such as
cu.usbmodem001 (on my PBG4) or cu.usbmodem0013 (plugged into the
keyboard on an iMac).
My question is, is this a hack, or a technique? :) In other words,
can I get away with it? I know that there is one problem with it in
that it will only find the last usbModem connected, but I think I
can live with that for now. Any opinions/alternate methods on
locating the correct device to connect to?
Yes. Use IOKit to locate all USB devices, then look at their type
until you find the proper one. Then grab that device's BSD path which
will be cu.usbmodem*, where * is the number you'll looking for.
-Tomas
--
# Tomas Zahradnicky, Jr
# The Czech Technical University
# Dept of Computer Science, FEE-CTU Prague
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.