Oberon/A2/Oberon.V24.Mod

MODULE V24 IN Oberon; (** AUTHOR "AFI"; PURPOSE "Backward compatibility module" *) (* Ensures the further validity of the earlier Aos.V24.Mod (object module V24.Obx) &#9;authored by "pjm". &#9;Most of the port control is now displaced to the new driver module &#9;V24.Obx module (Source V24.Mod *) IMPORT SYSTEM, Serials IN A2; CONST	(* Needed for compatibility *) &#9;(** Port aliases (check with NumberOfPorts) *) &#9;COM1* &#61; 1; COM2* &#61; 2;  COM3* &#61; 3;  COM4* &#61; 4; &#9;COM5* &#61; 5;  COM6* &#61; 6;  COM7* &#61; 7;  COM8* &#61; 8; &#9;(** Parity *) &#9;ParNo* &#61; Serials.ParNo;  ParOdd* &#61; Serials.ParOdd;  ParEven* &#61; Serials.ParEven; &#9;ParMark* &#61; Serials.ParMark;  ParSpace* &#61; Serials.ParSpace; &#9;(** Stop bits *) &#9;Stop1* &#61; Serials.Stop1;  Stop2* &#61; Serials.Stop2;  Stop1dot5* &#61; Serials.Stop1dot5; &#9;(** Modem control lines *) &#9;DTR* &#61; Serials.DTR;  RTS* &#61; Serials.RTS;	(** output *) &#9;Break* &#61; Serials.Break;	(** input/output - Bit 6 in LCR *) &#9;DSR* &#61; Serials.DSR; CTS* &#61; Serials.CTS;  RI* &#61; Serials.RI;  DCD* &#61; Serials.DCD;	(** input *) &#9;(** Receive error diagnostic *) &#9;OE* &#61; Serials.OverrunError; &#9;PE* &#61; Serials.ParityError; &#9;FE* &#61; Serials.FramingError; &#9;BI* &#61; Serials.BreakInterrupt; &#9;termination* &#61; Serials.Closed;	(* Indicates that the port is being closed *) &#9;Ok* &#61; Serials.Ok; PortInUse* &#61;  Serials.PortInUse; NoSuchPort* &#61;  Serials.NoSuchPort; &#9;WrongBPS* &#61; Serials.WrongBPS; WrongData* &#61;  Serials.WrongData; WrongParity* &#61;  Serials.WrongParity; &#9;WrongStop* &#61; Serials.WrongStop; VAR ports&#58; ARRAY Serials.MaxPorts + 1 OF Serials.Port; (* ports&#91;0&#93; is unused *) (** NumberOfPorts - Return number of ports available. *) PROCEDURE NumberOfPorts*&#58; SIGNED32; BEGIN &#9;RETURN Serials.MaxPorts; END NumberOfPorts; (** Start - Open a serial port (numbered from 0) connection. bps is the required bits per second. &#9;data is the number of bits per communication unit.  parity is the parity mode (Par &#9;values above). stop is the number of stop bits (Stop values above).  res returns 0 &#9;if ok, or error code on error.  1 means port already in use.  2 means no such port. &#9;3 means bad bps value.  4 means bad data/parity/stop.   DTR and RTS are enabled. *) PROCEDURE Start*(portNo, bps, data, parity, stop&#58; SIGNED32; VAR res&#58; INTEGER); VAR port &#58; Serials.Port; BEGIN &#9;res &#58;&#61; NoSuchPort; &#9;port &#58;&#61; Serials.GetPort(portNo); &#9;IF port # NIL THEN &#9;&#9;ports&#91;portNo&#93; &#58;&#61; port; &#9;&#9;ports&#91;portNo&#93;.Open(bps, data, parity, stop, res) &#9;END; END Start; (** Stop - Close the connection of the specified port. Effect on Modem Control lines is undefined. *) PROCEDURE Stop*(portNo&#58; SIGNED32); BEGIN &#9;ports&#91;portNo&#93;.Close END Stop; (** Send - Send a byte to the specified port. Waits until buffer space is available. res &#61; Ok iff ok. *) (** Antediluvian&#58; Kept for compatibility. - Use Writer... instead. *) PROCEDURE Send*(portNo&#58; SIGNED32; x&#58; SYSTEM.BYTE; VAR res&#58; INTEGER); BEGIN &#9;ports&#91;portNo&#93;.SendChar(CHR(x), res); END Send; (** SendBytes - Send n bytes to the specified port. Waits until buffer space is available. res &#61; Ok iff all ok. *) (** Antediluvian&#58; Kept for compatibility. - Use Writer... instead. *) PROCEDURE SendBytes*(portNo&#58; SIGNED32; VAR x&#58; ARRAY OF SYSTEM.BYTE; n&#58; SIGNED32; VAR res&#58; INTEGER); VAR i&#58; SIGNED32; BEGIN &#9;i &#58;&#61; 0; res &#58;&#61; Serials.Ok; &#9;WHILE (i # n) &#38; (res &#61; Serials.Ok) DO &#9;&#9;Send(portNo, x&#91;i&#93;, res); INC(i) &#9;END END SendBytes; (** Receive - Read one byte from the specified port. Waits until a byte is available. res &#61; Ok iff ok. *) PROCEDURE Receive*(portNo&#58; SIGNED32; VAR x&#58; SYSTEM.BYTE; VAR res&#58; INTEGER); VAR ch&#58; CHAR; BEGIN &#9;ports&#91;portNo&#93;.ReceiveChar(ch, res); &#9;x &#58;&#61; ch END Receive; (** ReceiveBytes - Read n bytes from the specified port. Waits until n bytes are available. res &#61; Ok iff ok. &#9;&#9;In case of error, the reception ends immediately at the first character in error. More data may be left in the buffer. *) PROCEDURE ReceiveBytes*(portNo&#58; SIGNED32; VAR x&#58; ARRAY OF SYSTEM.BYTE; n&#58; SIGNED32; VAR res&#58; INTEGER); VAR i&#58; SIGNED32; BEGIN &#9;i &#58;&#61; 0; res &#58;&#61; Serials.Ok; &#9;WHILE (i # n) &#38; (res &#61; Serials.Ok) DO &#9;&#9;Receive(portNo, x&#91;i&#93;, res); INC(i) &#9;END END ReceiveBytes; (** ClearMC - Clear the specified modem control lines. s may contain DTR, RTS &#38; Break. *) PROCEDURE ClearMC*(portNo&#58; SIGNED32; s&#58; SET); BEGIN &#9;ports&#91;portNo&#93;.ClearMC(s) END ClearMC; (** SetMC - Set the specified modem control lines. s may contain DTR, RTS &#38; Break. *) PROCEDURE SetMC*(portNo&#58; SIGNED32; s&#58; SET); BEGIN &#9;ports&#91;portNo&#93;.SetMC(s) END SetMC; (** GetMC - Return the state of the specified modem control lines. s contains &#9;the current state of DSR, CTS, RI, DCD &#38; Break. *) PROCEDURE GetMC*(portNo&#58; SIGNED32; VAR s&#58; SET); BEGIN &#9;ports&#91;portNo&#93;.GetMC(s) END GetMC; (** Available - Return the number of bytes available in the specified port&#39;s buffer. *) PROCEDURE Available*(portNo&#58; SIGNED32)&#58; SIZE; BEGIN &#9;RETURN ports&#91;portNo&#93;.Available END Available; END V24. System.Free V24 &#126;