Re: Locating a USB device
Re: Locating a USB device
- Subject: Re: Locating a USB device
- From: Chuck Rice <email@hidden>
- Date: Sun, 19 Jan 2003 14:54:40 -0800
At 11:35 PM +0100 1/19/03, Tomas Zahradnicky wrote:
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.
Not sure I understand your answer. I think that that is what I am
doing. It works fine on the machines I can test it on. Sounds like it
may be a "Technique". Thanks. -Chuck-
_______________________________________________
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.