| The
FT-100's serial communications port is very
versatile and may be used for many different
functions, and in many different ways. This
application note's purpose is to describe the
FT-100 serial port in more detail and go into
more depth about how to use if for the varied
functions.
There are several facts
concerning the serial port that might be helpful:
- Communications is always
half-duplex. In other words, data can go only one
direction at any
given time. If data
is being sent, all incoming data is ignored.
- RTS/CTS handshaking is always
used for data transmitted out the serial port.
There is no
handshaking for
incoming data.
- The serial input line is
connected to a hardware interrupt line in the
FT-100. If interrupts are
disabled, data cannot
be received. The only exception to this is when
the Direct Command
Mode is enabled and a
GET command is used to input one character.
- The serial input buffer can
hold up to 128 characters. If an attempt is made
to input more than
128 characters, the
BUFFER OVERFLOW error will result. In most cases,
when data is read
from the serial port,
the buffer is cleared. The exception to this
occurs when the GET
command is used with
Direct Command Mode disabled. Only one character
is removed from
the buffer in this
case.
- Any time Direct Command Mode
is enabled, and a carriage return (ASCII DH) is
received, the
input character
string will be interpreted as a direct command.
Also, with Direct Command
Mode and Echo
enabled, the backspace character ( 8) will cause
the FT-100 to send the
following character
string: 8, 2 H, 8 (backspace, space, backspace).
- The serial input buffer is
cleared of all data in the following conditions:
Program Starts
Program Ends Program
is Stopped Error condition Direct Command Mode
status is changed
(turned on, or turned
off) Beginning of the IN command Beginning of the
GET command if the
Direct Command Mode
is enabled Whenever the serial port is switched.
Note: This is still true
even if a 1041 Serial
Port Expander is not connected.
- If the Direct Command Mode is
disabled, and there has been incoming data, and a
WAIT
command is executed
(either WAIT pushbutton or program command), the
data will remain in
the serial input
buffer. If an attempt is made to execute a direct
command while in the "wait"
state, there will
most likely be a SYNTAX error, since the data in
the buffer will be interpreted
as a command.
SERIAL COMMUNICATIONS
COMMANDS
Following are the commands that
interact with the serial port, and a brief
description of each. (NOTE: See the operators
manual for more detailed information on these
commands)
PRINT - Sends
character strings out the serial port. While
characters are being transmitted, all incoming
data is ignored until the transmission is
finished. If the FT-100 sensed incoming data at
the end of the transmission, it will immediately
begin receiving. This can cause erroneous results
if the FT-100 begins receiving in the middle of a
character.
IN - Clears
the serial input buffer and waits for a character
string ending with a carriage return (ASCII DH).
Interrupts are not disabled during the IN
command, but the Direct Command Mode is disabled.
GET - Gets one
character from the serial port. The GET command
functions differently, depending on whether or
not the Direct Command Mode is enabled.
Direct Command Mode Enabled
-----
When the GET command begins,
the input buffer is cleared. The program then
waits for one character to be input. This
character is placed in the referenced string
variable. If no character is received, the only
way to get the program out of the GET command is
to press the RESET pushbutton. For this reason,
it is usually advisable to disable the Direct
Command Mode when using the GET command to input
characters.
Direct Command Mode Disabled
-----
All serial data is placed in
the serial input buffer in a first-in, first-out
fashion. The buffer can hold up to 128 characters
at any given time. The GET command will
"get" the first character and place it
in the referenced string variable. Interrupts
must be enabled for data to be received into the
buffer.
If the Direct Command Mode is
disabled, and a WAIT command is issued (WAIT
pushbutton or program command), there will likely
be characters in the input buffer. If attempt is
made to issue a direct command, a SYNTAX error
will usually result.
TWO-WAY COMMUNICATIONS
One of the safest methods used
when two devices must communicate with each other
is to use a form of software handshaking. This
can usually be as simple as placing a never-used
character on the end of the data string to signal
to the receiving device that it may begin sending
data. Two FT-100's can easily communicate with
each other using this method.
Most serial communications
troubles are caused by timing problems. This is
especially true when using a half-duplex system
with no handshaking. Be sure to allow enough time
for the receiving end to process its data. Also,
be aware of the contents of the input buffer at
all times. This also includes knowing when the
buffer is cleared, and when it is not.
Good luck.
NOTICE: Every effort has
been made to insure the accuracy of the
information contained in this document, however
Y-tek is not responsible for any consequences
resulting from erroneous or inaccurate
information.
|