This
information comes from site http://www.plcs.net/chapters/data30.htm
RS-232 Communications (hardware)
RS-232 communications is the most
popular method of plc to external device communications. Let's tackle it piece
by piece to see how simple it can be when we understand it.
RS-232 is an asynchronous
(a marching band must be "in sync" with each other so that when one
steps they all step. They are asynchronous in that they follow the band leader
to keep their timing) communications method. We use a binary system (1's and
0's) to transmit our data in the ASCII format. (American Standard Code for
Information Interchange- pronounced ASS-KEY) This code translates human
readable code (letters/numbers) into "computer readable" code (1's
and 0's). Our plcs serial port is used for transmission/reception of the data.
It works by sending/receiving a voltage. A
positive voltage is called a MARK and a negative voltage is called a SPACE.
Typically, the plc works with +/- 15volts. The voltage between +/- 3 volts is
generally not used and is considered noise.
There are 2
types of RS-232 devices.
The first is called a DTE device. This means Data Terminal Equipment and a
common example is a computer. The other type is called a DCE device. DCE means
Data Communications Equipment and a common example is a modem. Your plc may be
either a DTE or DCE device. Check your documentation.
The plc serial port works
by turning some pins on while turning other off. These pins each are dedicated
to a specific purpose. The serial port comes in 2 flavors-- a 25-pin type and a
9-pin type. The pins and their purposes are shown below. (This chart assumes
your plc is a DTE device)
|
9-PIN |
25-PIN |
PURPOSE |
|
1 |
1 |
frame ground |
|
2 |
3 |
receive data (RD) |
|
3 |
2 |
transmit data (TD) |
|
4 |
20 |
data terminal ready (DTR) |
|
5 |
7 |
signal ground |
|
6 |
6 |
data set ready (DSR) |
|
7 |
4 |
request to send (RTS) |
|
8 |
5 |
clear to send (CTS) |
|
9 |
22 |
ring indicator (RI) *only
for modems* |
Each pins purpose in
detail:
What happens when your plc and external device
are both DTE (or both DCE) devices? They can't talk to each other, that's what happens. The
picture below shows why 2 same type devices can't communicate with each other.

Notice that in the picture above, the receive data line
(pin2) of the first device is connected to the receive data line of the second
device. And the transmit data line (pin3) of the first device is connected to
the transmit data of the second device. It's like talking through a phone with
the wires reversed. (i.e. your mouth piece is connected directly to the other
parties mouthpiece and your ear piece is connected directly to the other
parties earpiece.) Obviously, this won't work well!
The solution is to use a null-modem connection
as shown below. This is
typically done by using a reverse (null-modem) cable to connect the devices.

To summarize everything, here's a typical
communications session. Both
devices are powered up. The plc is DTE and the external device is DCE.
The external device turns on DSR which tells the plc that's
it's powered up and "there". The PLC turns on RTS which is like
asking the external device "are you ready to receive some data?" The
external device responds by turning on it's CTS which says it's ok to for the
plc to send data. The plc sends the data on its TD terminal and the external
device receives it on its RD terminal. Some data is sent and received. After a
while, the external device can't process the data quick enough. So, it turns
off its CTS terminal and the plc pauses sending data. The external device
catches up and then turns its CTS terminal back on. The plc again starts
sending data on its TD terminal and the external device receives it on its RD
terminal. The plc runs out of data to send and turns off its RTS terminal. The
external device sits and waits for more data.
RS-232 Communications (software)
Now that we understand the hardware
part of the picture, let's dive right into the software part. We'll take a look
at each part of the puzzle by defining a few of the common terms. Ever
wondered what phrases like 9600-8-N-1 meant?
Do you use software-handshaking or hardware-handshaking at formal parties for a
greeting? If you're not sure, read on!
|
|
most significant
bits |
||||||||
|
least |
|
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
0 |
|
|
space |
0 |
@ |
P |
` |
p |
|
|
1 |
|
XON |
! |
1 |
A |
Q |
a |
q |
|
|
2 |
STX |
|
" |
2 |
B |
R |
b |
r |
|
|
3 |
ETX |
XOFF |
# |
3 |
C |
S |
c |
s |
|
|
4 |
|
|
$ |
4 |
D |
T |
d |
t |
|
|
5 |
|
NAK |
% |
5 |
E |
U |
e |
u |
|
|
6 |
ACK |
|
& |
6 |
F |
V |
f |
v |
|
|
7 |
|
|
' |
7 |
G |
W |
g |
w |
|
|
8 |
|
|
( |
8 |
H |
X |
h |
x |
|
|
9 |
|
|
) |
9 |
I |
Y |
i |
y |
|
|
A |
LF |
|
* |
: |
J |
Z |
j |
z |
|
|
B |
|
|
+ |
; |
K |
[ |
k |
{ |
|
|
C |
|
|
, |
< |
L |
\ |
l |
| |
|
|
D |
CR |
|
- |
= |
M |
] |
m |
} |
|
|
E |
|
|
. |
> |
N |
^ |
n |
~ |
|
|
F |
|
|
/ |
? |
O |
_ |
o |
|
|
The picture below shows how data leaves the serial port for
the character "E" (45h 100 0101b) and Even parity.

Another important thing that is sometimes used
is called software handshaking (flow control). Like the hardware handshaking we saw in the
previous chapter, software handshaking is used to make sure both devices are
ready to send/receive data. The most popular "character flow control"
is called XON/XOFF. It's very simple to understand. Simply put, the receiver
sends the XOFF character when it wants the transmitter to pause sending data.
When it's ready to receive data again, it sends the transmitter the XON character.
XOFF is sometimes referred to as the holdoff character and XON as the release
character.
The last thing we should know about is delimiters. A delimiter is simply added to the end of a message to tell
the receiver to process the data it has received. The most common is the
CR or the CR and LF pair. The CR (carriage return) is like the old typewriters.
(remember them??) When you reached the end of a line while typing, a bell would
sound. You would then grab the handle and move the carriage back to the start.
In other words, you returned the carriage to the beginning. (This is the same
as what a CR delimiter will do if you view it on a computer screen.) The
plc/external device receives this and knows to take the data from its buffer.
(where the data is stored temporarily before being processed) An LF (line feed)
is also sometimes sent with the CR character. If viewed on a computer screen
this would look like what happens on the typewriter when the carriage is returned
and the page moves down a line so you don't type over what you just typed.
Sometimes an STX and ETX pair is used for
transmission/reception as well. STX is "start of text" and ETX is
"end of text". The STX is sent before the data and tells the external
device that data is coming. After all the data has been sent, an ETX character
is sent.
Finally, we might also come across an ACK/NAK pair. This is
rarely used but it should be noted as well. Essentially, the transmitter sends
its data. If the receiver gets it without error, it sends back an ACK
character. If there was an error, the receiver sends back a NAK character and
the transmitter resends the data.
RS-232 has a lot of information to absorb, so
feel free to reread it. It's not so difficult if you take your time and think about each step.
Other communication methods get easier!