Serial.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:14k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       Serial.h
  3.  
  4.      Contains:   Asynchronous Serial Driver (.AIn/.AOut/.BIn/.BOut) Interfaces
  5.  
  6.      Version:    Technology: System 7.6+
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1985-2001 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __SERIAL__
  18. #define __SERIAL__
  19. #ifndef __MACTYPES__
  20. #include "MacTypes.h"
  21. #endif
  22. #if PRAGMA_ONCE
  23. #pragma once
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #if PRAGMA_IMPORT
  29. #pragma import on
  30. #endif
  31. #if PRAGMA_STRUCT_ALIGN
  32.     #pragma options align=mac68k
  33. #elif PRAGMA_STRUCT_PACKPUSH
  34.     #pragma pack(push, 2)
  35. #elif PRAGMA_STRUCT_PACK
  36.     #pragma pack(2)
  37. #endif
  38. enum {
  39.     baud150                     = 763,
  40.     baud300                     = 380,
  41.     baud600                     = 189,
  42.     baud1200                    = 94,
  43.     baud1800                    = 62,
  44.     baud2400                    = 46,
  45.     baud3600                    = 30,
  46.     baud4800                    = 22,
  47.     baud7200                    = 14,
  48.     baud9600                    = 10,
  49.     baud14400                   = 6,
  50.     baud19200                   = 4,
  51.     baud28800                   = 2,
  52.     baud38400                   = 1,
  53.     baud57600                   = 0
  54. };
  55. enum {
  56.     stop10                      = 16384,
  57.     stop15                      = -32768L,
  58.     stop20                      = -16384
  59. };
  60. enum {
  61.     noParity                    = 0,
  62.     oddParity                   = 4096,
  63.     evenParity                  = 12288
  64. };
  65. enum {
  66.     data5                       = 0,
  67.     data6                       = 2048,
  68.     data7                       = 1024,
  69.     data8                       = 3072
  70. };
  71. enum {
  72.     aData                       = 6,                            /* channel A data in or out (historical) */
  73.     aCtl                        = 2,                            /* channel A control (historical) */
  74.     bData                       = 4,                            /* channel B data in or out (historical) */
  75.     bCtl                        = 0                             /* channel B control (historical) */
  76. };
  77. enum {
  78.     dsrEvent                    = 2,                            /* flag for SerShk.evts */
  79.     riEvent                     = 4,                            /* flag for SerShk.evts */
  80.     dcdEvent                    = 8,                            /* flag for SerShk.evts */
  81.     ctsEvent                    = 32,                           /* flag for SerShk.evts */
  82.     breakEvent                  = 128                           /* flag for SerShk.evts */
  83. };
  84. enum {
  85.     xOffWasSent                 = 128,                          /* flag for SerStaRec.xOffSent */
  86.     dtrNegated                  = 64,                           /* flag for SerStaRec.xOffSent */
  87.     rtsNegated                  = 32                            /* flag for SerStaRec.xOffSent */
  88. };
  89. enum {
  90.     ainRefNum                   = -6,                           /* serial port A input */
  91.     aoutRefNum                  = -7,                           /* serial port A output */
  92.     binRefNum                   = -8,                           /* serial port B input */
  93.     boutRefNum                  = -9                            /* serial port B output */
  94. };
  95. enum {
  96.     swOverrunErr                = 1,                            /* serial driver error masks */
  97.     breakErr                    = 8,                            /* serial driver error masks */
  98.     parityErr                   = 16,                           /* serial driver error masks */
  99.     hwOverrunErr                = 32,                           /* serial driver error masks */
  100.     framingErr                  = 64                            /* serial driver error masks */
  101. };
  102. enum {
  103.     kOptionPreserveDTR          = 128,                          /* option bit used with Control code 16 */
  104.     kOptionClockX1CTS           = 64                            /* option bit used with Control code 16 */
  105. };
  106. enum {
  107.     kUseCTSOutputFlowControl    = 128,                          /* flag for SerShk.fCTS */
  108.     kUseDSROutputFlowControl    = 64,                           /* flag for SerShk.fCTS */
  109.     kUseRTSInputFlowControl     = 128,                          /* flag for SerShk.fDTR */
  110.     kUseDTRInputFlowControl     = 64                            /* flag for SerShk.fDTR */
  111. };
  112. enum {
  113.     sPortA                      = 0,                            /* Macintosh modem port */
  114.     sPortB                      = 1,                            /* Macintosh printer port */
  115.     sCOM1                       = 2,                            /* RS-232 port COM1 */
  116.     sCOM2                       = 3                             /* RS-232 port COM2 */
  117. };
  118. typedef SInt8                           SPortSel;
  119. /* csCodes for serial driver Control routines */
  120. enum {
  121.     kSERDConfiguration          = 8,                            /* program port speed, bits/char, parity, and stop bits */
  122.     kSERDInputBuffer            = 9,                            /* set buffer for chars received with no read pending */
  123.     kSERDSerHShake              = 10,                           /* equivalent to SerHShake, largely obsolete */
  124.     kSERDClearBreak             = 11,                           /* assert break signal on output */
  125.     kSERDSetBreak               = 12,                           /* negate break state on output */
  126.     kSERDBaudRate               = 13,                           /* set explicit baud rate, other settings unchanged */
  127.     kSERDHandshake              = 14,                           /* superset of 10, honors setting of fDTR */
  128.     kSERDClockMIDI              = 15,                           /* clock externally on CTS with specified multiplier */
  129.     kSERDMiscOptions            = 16,                           /* select clock source and DTR behavior on close */
  130.     kSERDAssertDTR              = 17,                           /* assert DTR output */
  131.     kSERDNegateDTR              = 18,                           /* negate DTR output */
  132.     kSERDSetPEChar              = 19,                           /* select char to replace chars with invalid parity */
  133.     kSERDSetPEAltChar           = 20,                           /* select char to replace char that replaces chars with invalid parity */
  134.     kSERDSetXOffFlag            = 21,                           /* set XOff output flow control (same as receiving XOff) */
  135.     kSERDClearXOffFlag          = 22,                           /* clear XOff output flow control (same as receiving XOn) */
  136.     kSERDSendXOn                = 23,                           /* send XOn if input flow control state is XOff */
  137.     kSERDSendXOnOut             = 24,                           /* send XOn regardless of input flow control state */
  138.     kSERDSendXOff               = 25,                           /* send XOff if input flow control state is XOn */
  139.     kSERDSendXOffOut            = 26,                           /* send XOff regardless of input flow control state */
  140.     kSERDResetChannel           = 27,                           /* reset serial I/O channel hardware */
  141.     kSERDHandshakeRS232         = 28,                           /* extension of 14, allows full RS-232 hardware handshaking */
  142.     kSERDStickParity            = 29,                           /* use mark/space parity */
  143.     kSERDAssertRTS              = 30,                           /* assert RTS output */
  144.     kSERDNegateRTS              = 31,                           /* negate RTS output */
  145.     kSERD115KBaud               = 115,                          /* set 115.2K baud data rate */
  146.     kSERD230KBaud               = 230                           /* set 230.4K baud data rate */
  147. };
  148. /* csCodes for serial driver Status routines */
  149. enum {
  150.     kSERDInputCount             = 2,                            /* return characters available (SerGetBuf) */
  151.     kSERDStatus                 = 8,                            /* return characters available (SerStatus) */
  152.     kSERDVersion                = 9,                            /* return version number in first byte of csParam */
  153.     kSERDGetDCD                 = 256                           /* get instantaneous state of DCD (GPi) */
  154. };
  155. struct SerShk {
  156.     Byte                            fXOn;                       /* XOn/XOff output flow control flag */
  157.     Byte                            fCTS;                       /* hardware output flow control flags */
  158.     unsigned char                   xOn;                        /* XOn character */
  159.     unsigned char                   xOff;                       /* XOff character */
  160.     Byte                            errs;                       /* errors mask bits */
  161.     Byte                            evts;                       /* event enable mask bits */
  162.     Byte                            fInX;                       /* XOn/XOff input flow control flag */
  163.     Byte                            fDTR;                       /* hardware input flow control flags */
  164. };
  165. typedef struct SerShk                   SerShk;
  166. struct SerStaRec {
  167.     Byte                            cumErrs;                    /* errors accumulated since last SerStatus() call */
  168.     Byte                            xOffSent;                   /* input (requested to be) held off by xOffWasSent or dtrNegated or rtsNegated */
  169.     Byte                            rdPend;                     /* incomplete read pending in I/O queue */
  170.     Byte                            wrPend;                     /* incomplete write pending in I/O queue */
  171.     Byte                            ctsHold;                    /* transmit disabled by hardware handshaking */
  172.     Byte                            xOffHold;                   /* transmit disabled by XOn/XOff handshaking */
  173.     Byte                            dsrHold;                    /* transmit disabled: external device not ready */
  174.     Byte                            modemStatus;                /* reports modem status according to SerShk.evts */
  175. };
  176. typedef struct SerStaRec                SerStaRec;
  177. #if OLDROUTINENAMES
  178. /* ********************************************************************************************* */
  179. /* The following constant names have been retired in favor of standard, more descriptive names.  */
  180. /* You can still compile old code by defining OLDROUTINENAMES. There were several constants that */
  181. /* were formerly available that have been removed, as they are now regarded as either private or */
  182. /* unsupported. We advise that you stop using any constants that are not defined in this file.   */
  183. /* ********************************************************************************************* */
  184. enum {
  185.     serdOptionClockExternal     = kOptionClockX1CTS,            /* option bit used with Control code 16 */
  186.     serdOptionPreserveDTR       = kOptionPreserveDTR            /* option bit used with Control code 16 */
  187. };
  188. /* csCodes for serial driver Control routines */
  189. enum {
  190.     serdReset                   = kSERDConfiguration,
  191.     serdSetBuf                  = kSERDInputBuffer,
  192.     serdHShake                  = kSERDSerHShake,
  193.     serdClrBrk                  = kSERDClearBreak,
  194.     serdSetBrk                  = kSERDSetBreak,
  195.     serdSetBaud                 = kSERDBaudRate,
  196.     serdHShakeDTR               = kSERDHandshake,
  197.     serdSetMIDI                 = kSERDClockMIDI,
  198.     serdSetMisc                 = kSERDMiscOptions,
  199.     serdSetDTR                  = kSERDAssertDTR,
  200.     serdClrDTR                  = kSERDNegateDTR,
  201.     serdSetPEChar               = kSERDSetPEChar,
  202.     serdSetPECharAlternate      = kSERDSetPEAltChar,
  203.     serdSetXOff                 = kSERDSetXOffFlag,
  204.     serdClrXOff                 = kSERDClearXOffFlag,
  205.     serdSendXOnConditional      = kSERDSendXOn,
  206.     serdSendXOn                 = kSERDSendXOnOut,
  207.     serdSendXOffConditional     = kSERDSendXOff,
  208.     serdSendXOff                = kSERDSendXOffOut,
  209.     serdChannelReset            = kSERDResetChannel,
  210.     serdSet230KBaud             = kSERD230KBaud                 /* set 230K baud data rate */
  211. };
  212. /* csCodes for serial driver Status routines */
  213. enum {
  214.     serdGetBuf                  = kSERDInputCount,
  215.     serdStatus                  = kSERDStatus,
  216.     serdGetVers                 = kSERDVersion
  217. };
  218. #endif  /* OLDROUTINENAMES */
  219. /*
  220.     The following interfaces are for the legacy high-level serial driver glue in
  221.     the interface libraries of your development system. They merely substitue for
  222.     the corresponding synchronous calls to PBControl and PBStatus.
  223.     They have not been updated as the serial driver API has evolved. Take note:
  224.         SerHShake does not support hardware input flow control. Use csCode 14.
  225.         SerStatus returns only the first six bytes of SerStaRec (through xOffHold).
  226. */
  227. #if CALL_NOT_IN_CARBON
  228. EXTERN_API( OSErr )
  229. SerReset                        (short                  refNum,
  230.                                  short                  serConfig);
  231. EXTERN_API( OSErr )
  232. SerSetBuf                       (short                  refNum,
  233.                                  Ptr                    serBPtr,
  234.                                  short                  serBLen);
  235. EXTERN_API( OSErr )
  236. SerHShake                       (short                  refNum,
  237.                                  const SerShk *         flags);
  238. EXTERN_API( OSErr )
  239. SerSetBrk                       (short                  refNum);
  240. EXTERN_API( OSErr )
  241. SerClrBrk                       (short                  refNum);
  242. EXTERN_API( OSErr )
  243. SerGetBuf                       (short                  refNum,
  244.                                  long *                 count);
  245. EXTERN_API( OSErr )
  246. SerStatus                       (short                  refNum,
  247.                                  SerStaRec *            serSta);
  248. #endif  /* CALL_NOT_IN_CARBON */
  249. #if PRAGMA_STRUCT_ALIGN
  250.     #pragma options align=reset
  251. #elif PRAGMA_STRUCT_PACKPUSH
  252.     #pragma pack(pop)
  253. #elif PRAGMA_STRUCT_PACK
  254.     #pragma pack()
  255. #endif
  256. #ifdef PRAGMA_IMPORT_OFF
  257. #pragma import off
  258. #elif PRAGMA_IMPORT
  259. #pragma import reset
  260. #endif
  261. #ifdef __cplusplus
  262. }
  263. #endif
  264. #endif /* __SERIAL__ */