PLC-to- Modem Communication Setup
A remotely located M-series PLC can be connected to a host PC via public-switch telephone network (PSTN), radio or cellular phone network. This can be accomplished by using two analog modems, one connected to the PLCs RS232 serial port, and another modem connected to the remote host PC as follow:
There are a some technical issues that need to be handled carefully in order to successfully implement the modem-linked host communications as described in the following sections.
1. Modem Connection
Modem1: The host PC may use any internal or external modem that can communicate at 2400 bps or faster. Connect the modem to the PC as instructed in the modems manual and connect the phone line to the phone jack on the back of the modem marked "WALL" or "Line".
Modem2: The modem to be attached to the PLC (modem2) must be an external modem with an RS232 connection port. Since modem are DCE type device, they most likely come with a female type DB25 or DB9 socket meant for plugging into the PCs RS232 port. Since the PLCs host link port is also a female DB9, we need to construct a DB9-male-to-DB25-male cable or DB9-male-to-DB9-male cable to link the PLC to the modem, as follow:
2. Communication Speed
When communicating via modems, there are two different definitions of communication speeds that you should be aware of:
The "DTE Speed" or "line rate" is the serial communication speed between the modem and the device connected to its RS232 port. Most modems can automatically detect the RS232 speed of the device and can assume any speed from 1200, 2400 all the way to 115,200 bps. The first ASCII character they receive from the device will determine the DTE speed that the modem will use to communicate with the device.
The "modem-to-modem communication speed" is what you read on the modem specifications, such as 33.6Kbps, 56Kbps etc. When two modems are connected, they automatically negotiate for the best speed to communicate between the two of them based on the quality of the phone connection and the maximum speed that both modems are able to achieve. We usually have no control of what speed they choose to communicate. But one thing is for sure, which is that the modem-to-modem speed is always lower than the DTE speed.
Since the default communication baud rate of the M-series PLCs RS232 serial port is 38,400 bps, the PLC should send a modem initialization string to the modem on the first scan pulse so that the modem can recognize its default DTE speed (i.e. 38,400 bps) in order to talk to the PLC. E.g. To reset the modem, you just have to send an ASCII string "ATZ" to the modem using the following TBASIC command:
PRINT #1 "ATZ"
If you want your modem to automatically answer to an incoming call (e.g. using TLServer 3.x modem dialing capability), then you should execute the following TBASIC statement:
PRINT #1 "ATS0=1"
The above statement will tell the modem to answer on first ring, you can also change the number 1 to other numbers, E.g. if ATS0=3 it will answer on the 3rd ring of the phone.
3. Software and Programming
The TLServer 3.x, which is part of the Internet TRiLOGI software suite, already includes built-in support for dialing a modem. Hence if you are using the PLC in passive answer mode only, all the PLC needs to do is to send a modem initialization string "ATS0=1" using the "1st.Scan" pulse to put the modem in auto-answer mode whenever the PLC is powered up. The PLC does not need to issue any more commands to the modem. Whenever a user wants to communicate with the PLC, he/she will first use the TLServer to dial and connect to the PLCs modem and when the connection is established, he/she will then be able to use the TRiLOGI client or the TRi-ExcelLink program to communicate with the PLC. The fact that the PLC is connected via modem and not via direct RS232 is totally transparent to the client programs. To prevent unauthorized access to the PLC, you may need to use the TBASIC command "SETPASSWORD" to set a protective password.
The great flexibility of the M-series PLCs becomes even more apparent when you realize that you can easily program the PLC to automatically dial in to the TLServer to perform a number of tasks, such as using the PLCs File Service to save or append data to hard disk files, send email to anyone via the Internet or even synchronize its real time clock with the host PC!
A number of examples have been included in the "C:\TRiLOGI\TL6\usr\samples\FileService_Modem" folder in TLServer 3.x. All these examples make use of a powerful yet easy to use custom function that was written entirely using the standard TBASIC commands (see source code listing in the text box below). You only need to create the following simple ladder circuit to use this function (assuming it is function #10):
D$ = "ATDT*802" '
store the phone number - you can put it elsewhere IF TESTIO(dialModem)=0 RETURN: ENDIF ' If DM[3990] > 0 it means a dialing action has started. IF DM[3990]=0 ' Use this DM as a flag A$ = INPUT$(1) SETLCD 4,1,A$ |
All you need to do is to copy and paste this custom function to your own ladder+BASIC program, then create an I/O with label name "DialModem" this may be an input, output, relay, timer or counter contact. The moment this I/O bit "DialModem" is turned on, the PLC will begin to execute the sequence of dialing the remote modem, waiting for a successful connection and then turning on an I/O bit with the label name "Connected". If the dialing cannot be completed within 30 seconds, this custom function will hang up and then re-dial. The process will be repeated indefinitely until either a successful connection is made or if the "DialModem" i/o has been turned OFF.
To disconnect from the modem (hang up), your PLC program just have to turn off the "Dialmodem" I/O bit and the abovementioned custom function will automatically perform the action of hanging up the modem.
Note:
Since the PLC does not have a carrier detect (CD) connection to the modem, therefore if the connection is lost after a successful initial connection, the PLC would have no way of knowing it immediately. Your program would have to detect this condition (e.g. if it sends a file service command and does not receive a "<OK>" acknowledgement string from the host). Once the PLC notes that the connection is lost, it can re-establish the connection by simply turning off the I/O bit with label name "Connected". (say, by executing the "CLRIO Connected" statement). As long as the "DialModem" I/O bit is on, the custom function will re-dial and attempt to make another connection if it notices that the "Connected" bit has been turned OFF for whatever reason.