Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Devices /
Chapter 7 - Serial Driver


Summary of the Serial Driver

Pascal Summary

Constants

CONST
   {values for the transmission rate in the SerConfig parameter}
   baud300        = 380;         {300 baud}
   baud600        = 189;         {600 baud}
   baud1200       = 94;          {1200 baud}
   baud1800       = 62;          {1800 baud}
   baud2400       = 46;          {2400 baud}
   baud3600       = 30;          {3600 baud}
   baud4800       = 22;          {4800 baud}
   baud7200       = 14;          {7200 baud}
   baud9600       = 10;          {9600 baud}
   baud14400      = 6;           {14400 baud}
   baud19200      = 4;           {19200 baud}
   baud28800      = 2;           {28800 baud}
   baud38400      = 1;           {38400 baud}
   baud57600      = 0;           {57600 baud}
   {values for the number of stop bits in the SerConfig parameter}
   stop10         = 16384;       {1 stop bit}
   stop15         = -32768;      {1.5 stop bits}
   stop20         = -16384;      {2 stop bits}
   {values for the parity in the SerConfig parameter}
   noParity       = 0;           {no parity}
   oddParity      = 4096;        {odd parity}
   evenParity     = 12288;       {even parity}
   {values for the number of data bits in the SerConfig parameter}
   data5          = 0;           {5 data bits}
   data6          = 2048;        {6 data bits}
   data7          = 1024;        {7 data bits}
   data8          = 3072;        {8 data bits}
   {bit mask values to test for indicated errors}
   swOverrunErr   = 1;           {software overrun error}
   breakErr       = 8;           {break occurred}
   parityErr      = 16;          {parity error}
   hwOverrunErr   = 32;          {hardware overrun error}
   framingErr     = 64;          {framing error}
   {bit mask values for the evts field in the SerShk record}
   ctsEvent       = 32;          {CTS change}
   breakEvent     = 128;         {break status change}
   {bit mask value for the xOffHold field of the SerStaRec record}
   dtrNegated     = 64;          {DTR signal was negated}
   xOffWasSent    = 128;         {XOFF character was sent}

Data Types

TYPE
   SerShk = 
   PACKED RECORD
      fXOn:    Byte;    {XON/XOFF output flow control flag}
      fCTS:    Byte;    {CTS output flow control flag}
      xOn:     Char;    {XON character}
      xOff:    Char;    {XOFF character}
      errs:    Byte;    {mask for errors that will terminate input}
      evts:    Byte;    {mask for status changes that cause events}
      fInX:    Byte;    {XON/XOFF input flow control flag}
      fDTR:    Byte;    {DTR input flow control flag (csCode 14 only)}
   END;
   SerStaRec =
   PACKED RECORD
      cumErrs:    Byte;    {cumulative errors}
      xOffSent:   Byte;    {XOFF sent as input flow control}
      rdPend:     Byte;    {read pending flag}
      wrPend:     Byte;    {write pending flag}
      ctsHold:    Byte;    {CTS flow control hold flag}
      xOffHold:   Byte;    {XOFF flow control hold flag}
   END;

Routines

FUNCTION SerReset		(refNum: Integer; serConfig: Integer): OSErr;
FUNCTION SerSetBuf		(refNum: Integer; serBPtr: Ptr; 
				serBLen: Integer): OSErr;
FUNCTION SerHShake		(refNum: Integer; flags: SerShk): OSErr;
FUNCTION SerSetBrk		(refNum: Integer): OSErr;
FUNCTION SerClrBrk		(refNum: Integer): OSErr;
FUNCTION SerGetBuf		(refNum: Integer; VAR count: LongInt): OSErr;
FUNCTION SerStatus		(refNum: Integer; VAR serSta: SerStaRec): OSErr;

C Summary

Constants

enum {
   /*values for the transmission rate in the SerConfig parameter*/
   baud300        = 380,         /*300 baud*/
   baud600        = 189,         /*600 baud*/
   baud1200       = 94,          /*1200 baud*/
   baud1800       = 62,          /*1800 baud*/
   baud2400       = 46,          /*2400 baud*/
   baud3600       = 30,          /*3600 baud*/
   baud4800       = 22,          /*4800 baud*/
   baud7200       = 14,          /*7200 baud*/
   baud9600       = 10,          /*9600 baud*/
   baud14400      = 6,           /*14400 baud*/
   baud19200      = 4,           /*19200 baud*/
   baud28800      = 2,           /*28800 baud*/
   baud38400      = 1,           /*38400 baud*/
   baud57600      = 0,           /*57600 baud*/
   /*values for the number of stop bits in the SerConfig parameter*/
   stop10         = 16384,       /*1 stop bit*/
   stop15         = -32768,      /*1.5 stop bits*/
   stop20         = -16384,      /*2 stop bits*/
   /*values for the parity in the SerConfig parameter*/
   noParity       = 0,           /*no parity*/
   oddParity      = 4096,        /*odd parity*/
   evenParity     = 12288,       /*even parity*/
   /*values for the number of data bits in the SerConfig parameter*/
   data5          = 0,           /*5 data bits*/
   data6          = 2048,        /*6 data bits*/
   data7          = 1024,        /*7 data bits*/
   data8          = 3072,        /*8 data bits*/
   /*bit mask values to test for indicated errors*/
   swOverrunErr   = 1,           /*software overrun error*/
   breakErr       = 8,           /*break occurred*/
   parityErr      = 16,          /*parity error*/
   hwOverrunErr   = 32,          /*hardware overrun error*/
   framingErr     = 64,          /*framing error*/
   /*bit mask values for the evts field in the SerShk record*/
   ctsEvent       = 32,          /*CTS change*/
   breakEvent     = 128,         /*break status change*/
   /*bit mask value for the xOffHold field of the SerStaRec record*/
   dtrNegated     = 64,          /*DTR signal was negated*/
   xOffWasSent    = 128          /*XOFF character was sent*/
};

Data Types

struct SerShk {
   char           fXOn;    /*XON/XOFF output flow control flag*/
   char           fCTS;    /*CTS output flow control flag*/
   unsigned char  xOn;     /*XON character*/
   unsigned char  xOff;    /*XOFF character*/
   char           errs;    /*mask for errors that will terminate input*/
   char           evts;    /*mask for status changes that cause events*/
   char           fInX;    /*XON/XOFF input flow control flag*/
   char           fDTR;    /*DTR input flow control flag (csCode 14 only)*/
};
typedef struct SerShk SerShk;
struct SerStaRec {
   char     cumErrs;       /*cumulative errors*/
   char     xOffSent;      /*XOFF sent as input flow control*/
   char     rdPend;        /*read pending flag*/
   char     wrPend;        /*write pending flag*/
   char     ctsHold;       /*CTS flow control hold flag*/
   char     xOffHold;      /*XOFF flow control hold flag*/
};
typedef struct SerStaRec SerStaRec;

Functions

pascal OSErr SerReset		(short refNum, short serConfig);
pascal OSErr SerSetBuf		(short refNum, Ptr serBPtr, short serBLen);
pascal OSErr SerHShake		(short refNum, const SerShk *flags);
pascal OSErr SerSetBrk		(short refNum);
pascal OSErr SerClrBrk		(short refNum);
pascal OSErr SerGetBuf		(short refNum, long *count);
pascal OSErr SerStatus		(short refNum, SerStaRec *serSta);

Assembly-Language Summary

Data Structures

Serial Handshake Record
0fXOnbyteXON/XOFF output flow control flag
1fCTSbyteCTS output flow control flag
2xOnbyteXOn character
3xOffbyteXOff character
4errsbytemask for errors that will terminate input
Xevtsbytemask for status changes that cause events
6fInXbyteXON/XOFF input flow control flag
7fDTRbyteDTR input flow control flag (csCode 14 only)

Serial Status Record
0cumErrsbytecumulative errors
1xOffSentbyteXOFF sent as input flow control
2rdPendbyteread pending flag
3wrPendbytewrite pending flag
4ctsHoldbyteCTS flow control hold flag
XxOffHoldbyteXOFF flow control hold flag

Device Manager Interface

Status Routines
CodeParametersFunction
2longReturn the number of bytes currently in the input data buffer (SerGetBuf).
86 bytesReturn status information (SerStatus).
9wordReturn driver version number.

Control Routines
CodeParametersFunction
8wordSet data rate and character frame (SerReset).
9long, wordSpecify either a new input buffer or the default buffer (SerSetBuf).
108 bytesSet software handshaking and other control information (SerHShake).
11 Deassert the break signal (SerClrBrk).
12 Assert the break signal (SerSetBrk).
13wordSet baud rate.
148 bytesEquivalent to control code 10, plus DTR handshaking.
16byteSet miscellaneous control options.
17 Assert DTR.
18 Negate DTR.
19byteSimple parity error replacement.
202 bytesExtended parity error replacement.
21 Set XOFF state.
22 Clear XOFF state.
23 Send XON for input flow control if XOFF was sent last.
24 Unconditionally send XON for input flow control.
25 Send XOFF for input flow control if XON was sent last.
26 Unconditionally send XOFF for input flow control.
27 Reset serial hardware channel.

Result Codes
noErr0No error
openErr-23Unable to open device driver
portInUse-97Port is in use
portNotCf-98Port is not configured


Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996