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
| 0 | fXOn | byte | XON/XOFF output flow control flag |
| 1 | fCTS | byte | CTS output flow control flag |
| 2 | xOn | byte | XOn character |
| 3 | xOff | byte | XOff character |
| 4 | errs | byte | mask for errors that will terminate input |
| X | evts | byte | mask for status changes that cause events |
| 6 | fInX | byte | XON/XOFF input flow control flag |
| 7 | fDTR | byte | DTR input flow control flag (csCode 14 only) |
Serial Status Record
| 0 | cumErrs | byte | cumulative errors |
| 1 | xOffSent | byte | XOFF sent as input flow control |
| 2 | rdPend | byte | read pending flag |
| 3 | wrPend | byte | write pending flag |
| 4 | ctsHold | byte | CTS flow control hold flag |
| X | xOffHold | byte | XOFF flow control hold flag |
Device Manager Interface
Status Routines
| Code | Parameters | Function |
| 2 | long | Return the number of bytes currently in the input data buffer (SerGetBuf). |
| 8 | 6 bytes | Return status information (SerStatus). |
| 9 | word | Return driver version number. |
Control Routines
| Code | Parameters | Function |
| 8 | word | Set data rate and character frame (SerReset). |
| 9 | long, word | Specify either a new input buffer or the default buffer (SerSetBuf). |
| 10 | 8 bytes | Set software handshaking and other control information (SerHShake). |
| 11 | | Deassert the break signal (SerClrBrk). |
| 12 | | Assert the break signal (SerSetBrk). |
| 13 | word | Set baud rate. |
| 14 | 8 bytes | Equivalent to control code 10, plus DTR handshaking. |
| 16 | byte | Set miscellaneous control options. |
| 17 | | Assert DTR. |
| 18 | | Negate DTR. |
| 19 | byte | Simple parity error replacement. |
| 20 | 2 bytes | Extended 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
noErr | 0 | No error |
| openErr | -23 | Unable to open device driver |
| portInUse | -97 | Port is in use |
| portNotCf | -98 | Port is not configured |