CommV24

MODULE CommV24;

	CONST
		bits4 = 0; bits5 = 1; bits6 = 2; bits7 = 3; stop15 = 4; stop2 = 5; even = 6; odd = 7;
		inXonXoff = 8; outXonXoff = 9; inRTS = 10; inDTR = 11; outCTS = 12; outDSR = 13;

	TYPE Connection = POINTER TO LIMITED RECORD END;

	PROCEDURE Open (device: ARRAY OF CHAR; baud: INTEGER; opts: SET; OUT conn: Connection);
	PROCEDURE Close (c: Connection);
	PROCEDURE SendByte (c: Connection; x: BYTE);
	PROCEDURE SendBytes (c: Connection; IN x: ARRAY OF BYTE; beg, len: INTEGER);
	PROCEDURE Available (c: Connection): INTEGER;
	PROCEDURE ReceiveByte (c: Connection; OUT x: BYTE);
	PROCEDURE ReceiveBytes (c: Connection; OUT x: ARRAY OF BYTE; beg, len: INTEGER);
	PROCEDURE SetBuffers (c: Connection; inpBufSize, outBufSize: INTEGER);
	PROCEDURE SetDTR (c: Connection; on: BOOLEAN);
	PROCEDURE SetRTS (c: Connection; on: BOOLEAN);
	PROCEDURE SetBreak (c: Connection; on: BOOLEAN);
	PROCEDURE CTSState (c: Connection): BOOLEAN;
	PROCEDURE DSRState (c: Connection): BOOLEAN;
	PROCEDURE CDState (c: Connection): BOOLEAN;

END CommV24.


Simple procedural interface to V24 and similar serial devices.


CONST bits4, bits5, bits6, bits7
Number of data bits. These flags may be included in the opts set of procedure Open. At most one of them may be included. If none is included, 8 bits are chosen.

CONST stop15, stop2
Number of stop bits (1.5 or 2). These flags may be included in the opts set of procedure Open. At most one of them may be included. If none is included, one stop bit is chosen.

CONST even, odd
Parity checking. These flags may be included in the opts set of procedure Open. At most one of them may be included. If none is included, no parity checking is chosen.

CONST inXonXoff, outXonXoff
XOn/XOff flow control for input and for output direction. These flags may be included in the opts set of procedure Open.

CONST inRTS, inDTR, outCTS, outDSR
These flags may be included in the opts set of procedure Open.

TYPE Connection
LIMITED
Connection handle. It represents a V24 connection through a particular device.


PROCEDURE Open (device: ARRAY OF CHAR; baud: INTEGER; opts: SET; OUT conn: Connection)
Opens a given device (e.g., "COM3:") with the given baudrate and options. Note that a device to which a connection is already open cannot be open a second time before it is closed explicitly.

Post
opening succeeded
	conn # NIL
opening failed
	conn = NIL

PROCEDURE Close (c: Connection)
Closes an open connection.

Pre
c # NIL	20
c is open	21

PROCEDURE SendByte (c: Connection; x: BYTE)

Pre
c # NIL	20
c is open	21

PROCEDURE SendBytes (c: Connection; IN x: ARRAY OF BYTE; beg, len: INTEGER)

Pre
c # NIL	20
c is open	21
LEN(x) >= beg + len	22
len > 0	23

PROCEDURE Available (c: Connection): INTEGER

Pre
c # NIL	20
c is open	21

PROCEDURE ReceiveByte (c: Connection; OUT x: BYTE)

Pre
c # NIL	20
c is open	21

PROCEDURE ReceiveBytes (c: Connection; OUT x: ARRAY OF BYTE; beg, len: INTEGER)

Pre
c # NIL	20
c is open	21
LEN(x) >= beg + len	22
len > 0	23

PROCEDURE SetBuffers (c: Connection; inpBufSize, outBufSize: INTEGER)

Pre
c # NIL	20
c is open	21

PROCEDURE SetDTR (c: Connection; on: BOOLEAN)

Pre
c # NIL	20
c is open	21
~(inDTR IN c.opts)	22

PROCEDURE SetRTS (c: Connection; on: BOOLEAN)

Pre
c # NIL	20
c is open	21
~(inRTS IN c.opts)	22

PROCEDURE SetBreak (c: Connection; on: BOOLEAN)

Pre
c # NIL	20
c is open	21

PROCEDURE CTSState (c: Connection): BOOLEAN

Pre
c # NIL	20
c is open	21

PROCEDURE DSRState (c: Connection): BOOLEAN

Pre
c # NIL	20
c is open	21

PROCEDURE CDState (c: Connection): BOOLEAN

Pre
c # NIL	20
c is open	21
