الأحد، 5 يناير 2014

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:
  • frame ground- This pin should be internally connected to the chassis of the device.
  • receive data- This pin is where the data from the external device enters the plc serial port.
  • transmit data- This pin is where the data from the plc serial port leaves the plc enroute to the external device.
  • data terminal ready- This pin is a master control for the external device. When this pin is 1 the external device will not transmit or receive data.
  • signal ground- Since data is sent as + or - voltage, this pin is the ground that is referenced.
  • data set ready- Usually external devices have this pin as a permanent 0 and the plc basically uses it to determine that the external device is powered up and ready.
  • request to send- This is part of hardware handshaking. When the plc wants to send data to the external device it sets this pin to a 0. In other words, it sets the pin to a 0 and basically says "I want to send you data. Is it ok?" The external device says it's OK to send data by setting its clear to send pin to 0. The plc then sends the data.
  • clear to send- This is the other half of hardware handshaking. As noted above, the external device sets this pin to 0 when it is ready to receive data from the plc.
  • ring indicator- only used when the plc is connected to a modem.
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.
DTE to DTE communication
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.
correct DTE-DTE communication
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

0 التعليقات:

إرسال تعليق