Help: CommSerial is misbehaving

Greg Edwards (gedwards@Csli.Stanford.EDU)
Wed, 3 Sep 1997 22:59:14 -0700 (PDT)

I'm trying to use CommSerial to connect to the serial port but I'm getting
a TRAP 60 (PostCondition violoation). Any ideas?

I open it using:

CommSerial.portSett.port.index := 1;
CommSerial.portSett.baud.index := 5;
CommSerial.portSett.flow.index := 0;
CommSerial.ApplySettings;
CommSerial.NewStream ("COM2","COM1",stream,res);

Then I send a string to the stream (but since it only accepts
ARRAY OF BYTE I have to copy the string into a temporary array).

PROCEDURE Send* (IN str: ARRAY OF CHAR; save: BOOLEAN);
VAR cnt,sendCnt, i: INTEGER; byte: ARRAY 50 OF BYTE;
BEGIN
FOR i := 0 TO (LEN(str$)-1) DO
byte[i] := SHORT(SHORT(ORD(str[i])));
END;
byte[LEN(str$)] := 0;

cnt := LEN(str$);
stream(CommSerial.Stream).WriteBytes(byte,0,cnt,sendCnt);
END Send;

When I execute this code to send the string "01234567890123456789",
it sends 15 or 16 of the bytes and then blows up, saying:

TRAP 60 (postcondition violated)
CommSerial.Stream.WriteBytes [0000035AH]
.beg INTEGER 0
.done INTEGER 0
.len INTEGER 29
.n INTEGER 5822760
.ret INTEGER 10
.s CommSerial.Stream [19EE77E0H]
.written INTEGER 16
.x ARRAY 50 OF BYTEelement

Any ideas???
I appreciate the help.
-greg edwardss