80 lines
1.9 KiB
Plaintext
80 lines
1.9 KiB
Plaintext
|
(* Version 1.10, Nov 1984 *)
|
|||
|
DEFINITION MODULE RS232Polling;
|
|||
|
(*
|
|||
|
Polled input/output via the RS-232 asynchronous
|
|||
|
serial port
|
|||
|
|
|||
|
Since this module does not use interrupts, it is the
|
|||
|
responsibility of the programmer to poll (by calling
|
|||
|
'Read' or 'BusyRead') frequently enough to ensure that
|
|||
|
no characters are lost.
|
|||
|
|
|||
|
Derived from the Lilith Modula-2 system developed by the
|
|||
|
group of Prof. N. Wirth at ETH Zurich, Switzerland.
|
|||
|
*)
|
|||
|
|
|||
|
|
|||
|
EXPORT QUALIFIED
|
|||
|
Init, BusyRead, Read, Write;
|
|||
|
|
|||
|
|
|||
|
PROCEDURE Init (baudRate: CARDINAL;
|
|||
|
stopBits: CARDINAL;
|
|||
|
parityBit: BOOLEAN;
|
|||
|
evenParity: BOOLEAN;
|
|||
|
nbrOfBits: CARDINAL;
|
|||
|
VAR result: BOOLEAN);
|
|||
|
(*
|
|||
|
- Initialize the serial port.
|
|||
|
|
|||
|
in: baudRate transmission speed,
|
|||
|
stopBits number of stop bits (usually 1 or 2),
|
|||
|
parityBit if TRUE, parity is used, otherwise not,
|
|||
|
evenParity if parity is used, this indicates
|
|||
|
even/odd,
|
|||
|
nbrOfBits number of data bits (usually 7 or 8),
|
|||
|
|
|||
|
out: result TRUE if the initialization was
|
|||
|
completed.
|
|||
|
|
|||
|
The legal values for the parameters depend on the
|
|||
|
implementation (e.g. the range of supported baud rates).
|
|||
|
*)
|
|||
|
|
|||
|
|
|||
|
PROCEDURE BusyRead (VAR ch: CHAR; VAR received: BOOLEAN);
|
|||
|
(*
|
|||
|
- Read a character from serial port, if one has been
|
|||
|
received.
|
|||
|
|
|||
|
out: ch the character received, if any,
|
|||
|
received TRUE if a character was received.
|
|||
|
|
|||
|
If no character has been received, then ch = 0C, and
|
|||
|
received = FALSE.
|
|||
|
*)
|
|||
|
|
|||
|
|
|||
|
PROCEDURE Read (VAR ch: CHAR);
|
|||
|
(*
|
|||
|
- Read a character from the serial port.
|
|||
|
|
|||
|
out: ch the character received.
|
|||
|
|
|||
|
As opposed to BusyRead, Read waits for a character to
|
|||
|
arrive.
|
|||
|
*)
|
|||
|
|
|||
|
|
|||
|
PROCEDURE Write (ch: CHAR);
|
|||
|
(*
|
|||
|
- Write a character to the serial port.
|
|||
|
|
|||
|
in: ch character to send.
|
|||
|
|
|||
|
Note: no interpretation of characters is made.
|
|||
|
*)
|
|||
|
|
|||
|
|
|||
|
END RS232Polling.
|
|||
|
|