[comp.sys.mac.programmer] Need help with serial ports

chou@cs.washington.edu (Pai Chou) (04/25/91)

I wrote a terminal emulator program.  It works fine when I'm
connected directly as a terminal, or connected to certain
brands of modem (e.g. SupraModem 2400).  However,
it would freeze on other brands, including Apple MacPortable internal
2400 and a few others.

I tried to locate where the freezing occurs.  It turns out
the FSWrite() call is made but never returns.

Can someone tell me what I might have done wrong?
I did the following initializations and they all return noErr.
(pascal syntax; listed in order of execution but not actual
 program segment)

err := RAMSDOpen(sPortA);
err := OpenDriver('.AOut', serOutNum);
err := SerSetBuf(serOutNum, @outbuf, BUFSIZ);
err := OpenDriver('.AIn', serInNum);
err := SerSetBuf(serInNum, @inbuf, BUFSIZ);
err := SerReset(serInNum, baud+stopBit+parity+dataBit);
err := SerReset(serOutNum, baud+stopBit+parity+dataBit);
flags.fXon := 0;
flags.fInX := 0;
fln := chr(17);
flags.xOff := chr(19);
flags.fCTS :=  1;
err := SerHShake(serInNum, flags);
err := SerHShake(serOutNum, flags);

Do these initialization calls look ok?
All of them return noErr.

then I have a loop (which also returns noErr)
	err := SerGetBuf(serInNum, icount);
	if icount > 0 then begin
		err := FSRead(serInNum, icount, @buf2);
...

On a key down or file dump or paste,
I call err := FSWrite(serOutNum, sz, @buf1);

The FSWrite is executed but it never returns.
I have no idea why.  Again, this works fine with direct
serial connection and certain modems, but not other modems.

Another strange thing is that with the modem on,
I would get the System Error bomb (id = 2) if I run it under 
Mac Taiwanese OS; but again, I have no problem with direct
serial connection.

Thanks in advance for any help or pointer to sample code.

Pai Chou
chou@june.cs.washington.edu