• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Locating a USB device
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locating a USB device


  • Subject: Re: Locating a USB device
  • From: Chuck Rice <email@hidden>
  • Date: Sun, 19 Jan 2003 17:22:49 -0800

At 1:41 AM +0100 1/20/03, Tomas Zahradnicky wrote:
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-

No that is not. If I remember correcly, you are trying to figure out which number is after the cu.usbmodem. This is how to determine it. Look into

<http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Serial/SerialPortSample.htm>

on how to find modems and use them.

I must still be missing something or miss-communicating. That is the example that Andraes Objects are based on, but the Apple example is a C example, not, Objective-C, and it will always return the first serial port found, not all the ports found. In my case, that is the internal modem, not the USBmodem. Andraes Example Class builds on the Apple example wrapping a class structure around the Sample code. (see code below). But that is not my question.

The code already gives me the number after the cu.usbmodem. Instead, my question involves asking "is really all right", once I have used the sample code method to return ALL the serial ports, to rely on the fact that 'normal' modems will come back as "cu.modem*" and a cell phone will come back connected as a "cu.usbmodem*". My code scans the list of serial devices returned by the serial port iterator and based on the leading cu.usbmodem, selects a device. What I do not know is what other serial devices (such as PDAs) will report when they are also connected to the USB ports. Will I end up trying to connect to the wrong device by using this method. I think that there is a chance, so after further thought, I think that I am going to need to follow up with some AT commands to ask the selected device to send me its name.

Thanks for your help though. Makes me think. -Chuck-



-(id)init
{
kern_return_t kernResult; // on PowerPC this is an int (4 bytes)
/*
* error number layout as follows (see mach/error.h):
*
* hi lo
* | system(6) | subsystem(12) | code(14) |
*/
io_iterator_t serialPortIterator;
AMSerialPort *serialPort;

if (portList != nil) {
// rescan ports ***********************************************
} else {
[super init];
portList = [[NSMutableArray array] retain];

kernResult = [self findSerialPorts:&serialPortIterator];
do
{
serialPort = [self getNextSerialPort:serialPortIterator];
if (serialPort != NULL)
{
[portList addObject:serialPort];
}
}
while (serialPort != NULL);
IOObjectRelease(serialPortIterator); // Release the iterator.
}
return self;
}


-(kern_return_t)findSerialPorts:(io_iterator_t *)matchingServices
{
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;

kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (KERN_SUCCESS != kernResult)
{
printf("IOMasterPort returned %d\n", kernResult);
}
// Serial devices are instances of class IOSerialBSDClient
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
if (classesToMatch == NULL)
{
printf("IOServiceMatching returned a NULL dictionary.\n");
}
else
CFDictionarySetValue(classesToMatch,
CFSTR(kIOSerialBSDTypeKey),
CFSTR(kIOSerialBSDAllTypes));
kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, matchingServices); if (KERN_SUCCESS != kernResult)
{
printf("IOServiceGetMatchingServices returned %d\n", kernResult);
}
return kernResult;
}
_______________________________________________
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.

References: 
 >Locating a USB device (From: Chuck Rice <email@hidden>)
 >Re: Locating a USB device (From: Tomas Zahradnicky <email@hidden>)
 >Re: Locating a USB device (From: Chuck Rice <email@hidden>)
 >Re: Locating a USB device (From: Tomas Zahradnicky <email@hidden>)

  • Prev by Date: Re: Hacker's Fate
  • Next by Date: Re: Examples of applications developed with Cocoa?
  • Previous by thread: Re: Locating a USB device
  • Next by thread: [self correctDeleteButton];
  • Index(es):
    • Date
    • Thread