This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.
You call OpenDriver for the names "\p.AOut" and "\p.AIn" to get at
the modem port, and "\p.BOut" and "\p.BIn" for the printer port. The
function RAMSDOpen was designed for the original Mac with 128 kB of
memory and 64 kB of ROM, and has been extinct for several years.
However, many users use their serial ports for MIDI, LocalTalk, graphic
tablets, or what have you and have installed an additional serial port
card to get more ports. What you SHOULD do as a good application is to
use the Comm Toolbox Resource Manager to search for serial resources;
this requires that the Comms Toolbox is present (true on earlier System
6 with an INIT, on later System 6 and System 7 always, as well as on
A/UX) and that you have initialized the comms resource manager. The
exact code follows (adapted from Inside Mac Comms Toolbox):
*code*
#include "CommResources.h"
OSErr
FindPorts ( Handle * portOutNames , Handle * portInNames , Handle * names , Handle * iconHandles ) {
OSErr ret = noErr ;
short old = 0 ;
CRMRec theCRMRec , * found ;
CRMSerialRecord * serial ;
* portOutNames = NewHandle ( 0L ) ;
* portInNames = NewHandle ( 0L ) ;
* names = NewHandle ( 0L ) ;
* iconHandles = NewHandle ( 0L ) ;
while ( ! ret ) {
theCRMRec . crmDeviceType = crmSerialDevice ;
theCRMRec . crmDeviceID = old ;
found = ( CRMRec * ) CRMSearch ( ( QElementPtr ) & theCRMRec ) ;
if ( found ) {
serial = ( CRMSerialRecord * ) found -> crmAttributes ;
old = found -> crmDeviceID ;
PtrAndHand ( & serial -> outputDriverName , * portOutNames ,
sizeof ( serial -> outputDriverName ) ) ;
PtrAndHand ( & serial -> inputDriverName , * portInNames ,
sizeof ( serial -> inputDriverName ) ) ;
PtrAndHand ( & serial -> name , * names ,
sizeof ( serial -> name ) ) ;
PtrAndHand ( & serial -> deviceIcon , * iconHandles ,
sizeof ( serial -> deviceIcon ) ) ;
} else {
break ;
}
}
return err ;
}
*end*
 
Continue to: