COM Port Handshaking

Dar Scott dsc at swcp.com
Sat Apr 13 05:30:01 EDT 2002


On Saturday, April 13, 2002, at 02:49 AM, Peter Reid wrote:

> I've been experimenting with these, but find that sometimes only 
> part of the command is received by the equipment.  All commands 
> are 3 character codes with optional numeric parameters. All 
> commands are in 7-bit ASCII.

You mean something like this?

RD%23,19,0,0<cr>

I'm surprised that this is a problem.  Hmmm.  It may be the 
software is processing characters as they come in and doing the 
math for numeric parameters as they come in.  If the 
microcontroller has no UART, the software may be shifting data in 
itself.  If that is the case, the controller has only a short time 
to process each byte.

Try setting the stop bits to 2.

Try typing in commands from HyperTerminal with or without hardware 
handshaking.  I think "hardware handshaking" on it is RTS-CTS.  In 
any case, make sure the thing works with slow typing.  If not, then 
handshaking will not help.


> What I'm not sure of is the correct handshaking protocol and how I 
> do this in Rev. How do I use CTS, DTR etc. assuming that these 
> lines are being used (which the equipment manual implies that they 
> are). Are there any messages associated with the COM ports that I 
> can trigger on or wait on?

It is set when you open.  The serial driver will take care of the 
handshaking.  You don't have to do anything.  Just keep the device 
open.  However, you may need to wait until you get a complete 
response before you send another command, depending on the 
equipment.

The handshake lines were defined for terminal modem connections and 
equipment makers use them in inconsistent ways.

The Revolution docs don't exactly match the mode docs.  Also, the 
meaning may not be clear.  In some cases "on" means always on while 
the com port is open.  In some cases it means it is used as a 
handshake.  Look at the mode docs.  Here is my summary of mode:

octs=on      The computer looks at the CTS line (input) to control 
data output.
odsr=on      The computer looks at the DSR line (input) to control 
output.
dtr=on/off   The computer sets the DTR line (output) to the fixed value.
dtr=hs       The computer flips the DTR line as needed to control 
data input.
rts=on/off/hs    Like DTR
rts=tg       Use for RS485 control; RTS is on only then transmitting
idsr=on      Ignore input characters that come in while DSR 
(input=power on) is off.

Typical settings are octs=on rts=hs.

(Some codes are not in the Revolution docs.  It may be they don't 
apply to Macs or are ignored in all cases.)

If you still have trouble...

If you are using 3.1 or 95, upgrade.  Some old serial drivers get 
confused when handshake lines flip too fast.

Put in delays in your output scripts.

Scope on the handshake and data lines.

Dar Scott




More information about the use-livecode mailing list