|##########|
|#MAGIC   #|CLABLLEH
|#PROJECT #|"Importall"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx-x-x--xx----x-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|xx---xxxxx------
|##########|
DEFINITION MODULE Serial;
(* $A- *)
FROM System     IMPORT LONGSET,SysStringPtr;
FROM T_Exec     IMPORT IOCommand, nonstdVAL, IOStdReq, DevicePtr,
                       IOFlagSet, IOFlags;
FROM Resources  IMPORT ContextPtr;
FROM Utility    IMPORT StdTags;

CONST
  query       = IOCommand( nonstdVAL );
  break       = IOCommand( nonstdVAL + 1 );
  setParams   = IOCommand( nonstdVAL + 2 );
  active      = IOFlagSet:{ IO4 };
  abort       = IOFlagSet:{ IO5 };
  queued      = IOFlagSet:{ IO6 };
  bufrRead    = IOFlagSet:{ IO7 };

TYPE
  SerFlags       = (parityOn,parityOdd,sevenWire,queuedBrk,radBoogie,
                    shared,eofMode,xDisabled);
  SerFlagSet     = SET OF SerFlags;

  ExtSerFlags    = (mark,mSpOn,esf2,esf3,esf4,esf5,esf6,esf7,esf8,esf9,
                    esf10,esf11,esf12,esf13,esf14,esf15,esf16);
  ExtSerFlagSet  = SET OF ExtSerFlags;
  Status         = (busy,paperOut,select,dataSetReady,clearToSend,
                    carrierDetect,readyToSend,dataTerminalReady,overrun,
                    wroteBreak,readBreak,xOffWrite,xOffRead);
  StatusSet      = SET OF Status;

  Error          = (e0,devBusy,baudMismatch,invBaud,bufErr,invParam,
                    lineErr,notOpen,portReset,parityErr,initErr,
                    timerErr,bufOverflow,nodsr,nocts,detectedBreak);

  IOSerial       = RECORD OF IOStdReq
                     ctlChar   : LONGCARD;
                     rBufLen   : LONGCARD;
                     extFlags  : ExtSerFlagSet;
                     baud      : LONGCARD;
                     brkTime   : LONGCARD;
                     termArray : ARRAY [0..1] OF LONGCARD;
                     readLen   : SHORTCARD;
                     writeLen  : SHORTCARD;
                     stopBits  : SHORTCARD;
                     serFlags  : SerFlagSet;
                     status    : StatusSet;
                   END;
  IOSerialPtr    = POINTER TO IOSerial;


  IOSerialTags   = TAGS OF StdTags
                     ctlChar   : LONGCARD;
                     rBufLen   : LONGCARD;
                     extFlags  : ExtSerFlagSet;
                     baud      : LONGCARD;
                     brkTime   : LONGCARD;
                     termArray0: LONGCARD;
                     termArray1: LONGCARD;
                     readLen   : SHORTCARD;
                     writeLen  : SHORTCARD;
                     stopBits  : SHORTCARD;
                     serFlags  : SerFlagSet;
                     name      : SysStringPtr;
                   END;


CONST
  ringIndicator  = select;

EXCEPTION SetParamsFailed : "SetParams failed";


PROCEDURE OpenSerial(context : ContextPtr:=NIL;
                     tags    : LIST OF IOSerialTags):IOSerialPtr;

PROCEDURE CloseSerial(VAR request : IOSerialPtr);


GROUP
  All  = query,break,setParams,active,abort,queued,bufrRead,SerFlags,
         SerFlagSet,ExtSerFlags,ExtSerFlagSet,Status,StatusSet,Error,
         IOSerial,IOSerialPtr,ringIndicator,OpenSerial,CloseSerial,
         T_Exec.ExecIOGrp;


END Serial.

