Instrotech Application : PLC SMS
This application note describes how to send a Short Message Service SMS from a National Automation and Industrial Systems NAIS Programmable Logic Controler PLC
The PLC must have one free RS232 port. The PLC program will send messages via this port and receive status information. The port can not be a programming port as the protocol is different.
CELL PHONE SIM CARD
A contract or Pay As You Go PAYG SIM card can be used
Put the sim card into a normal cell phone first and disable the pin code request
Check the message service centre number eg. MTN PAYG +27831000113
CELL PHONE MODEM
A Wavecom model WMOD2 cell phone modem is used to access the SMS mail centre. This modem behaves the same as a computer modem. There are also additional commands for sms etc these start with AT+
The modem must be setup correctly with a computer first using a terminal program.
The modem cable is 1:1 eg. TX to Tx, RX to Rx. These lines have been swapped inside the modem
| Computer |
Description |
Wavecom WMOD2 |
2 |
RXD |
6 |
3
|
TXD |
2 |
7 |
RTS |
12 |
8 |
CTS |
11 |
4 |
DTR |
8 |
5 |
GND |
9 |
DSUB9 FEM CABLE |
|
DSUB9/15 MALE CABLE |
Setup computer port to 9600 baud, 8 data, 1 stop, no parity, rts line set (Hardware handshaking)
Send to modem
|
Modem returns |
Description |
| AT(crlf) |
AT(crlf) (crlf)OK(crlf) |
The first AT sets up the modem |
| ATE0(crlf) |
(crlf)OK(crlf) |
Turn off echo |
| AT+ICF=5,0(crlf) |
(crlf)OK(crlf) |
7 data, odd parity, 1 stop |
Note: The modem must be setup with a total of 10 bits. If parity is required then only seven data bits are available
Setup computer port : 9600, 7 data, odd parity, 1 stop, rts set
| Send to modem |
Modem returns |
Description |
| AT(crlf) |
(crlf)OK(crlf) |
Test new settings |
| AT+CMGF=1(CRLF) |
(crlf)OK(crlf) |
sms format = text |
| AT+CBST=71,0,0(crlf) |
(crlf)OK(crlf) |
9600 V110, asynch, transparent |
| AT+CICB=0(crlf) |
(crlf)OK(crlf) |
Set incomming data |
| AT+CMEE=0(crlf) |
(crlf)OK(crlf) |
No result codes |
| AT+CSDH=0(crlf) |
(crlf)OK(crlf) |
No text parameters |
| AT+CRC=0(crlf) |
(crlf)OK(crlf) |
No incomming messages |
| AT+IFC=0,0(crlf) |
(crlf)OK(crlf) |
No RTS, CTS lines |
| AT&DO(crlf) |
(crlf)OK(crlf) |
No DTR line |
| ATS0=1(crlf) |
(crlf)OK(crlf) |
Auto answer |
| AT&W(crlf) |
(crlf)OK(crlf) |
Save setup to ee |
To check a setting add a ? after the command. To check the available options add a ? after the equals
PLC SETUP
Once the modem has been setup it can be plugged into the plc. The PLC general RS232 port is used and setup : General use, 7 data bit, odd parity, 1 stop, terminator = ETX, header = no stx, baud 9600, disable modem. The modem option only sends AT&F at startup and is not required.
The plc modem cable is as follows.
| Fp0 |
Description |
WMOD2 |
S |
TX |
2 |
R |
RX |
6 |
G |
GND |
9 |
RS232 Option Con |
|
DSUB 9/15 Male |
PLC PROGRAM
The PLC can send a command to the modem to check if it is there
The first data in the plc transmit area is reserved for the TX command
| 50 |
51 |
|
52 |
|
DATA register number |
| |
A |
T |
CR |
LF |
Characters to send |
| |
T |
A |
LF |
CR |
PLC Data has hi and lo bytes swapped |
| |
54 |
41 |
0A |
0D |
ASCII hex values |
ASCII American standard code for information interchange
The modem returns (crlf) OK (crlf)
The plc program sends a command to the modem to tell it to send a sms.
## ## ### #### = telephone number to send sms to eg 27 11 555 1234 (space)
The telephone number must end with CR only
| 51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
| A |
T |
+ |
C |
M |
G |
S |
= |
" |
+ |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
" |
cr |
sp |
| T |
A |
C |
+ |
G |
M |
= |
S |
+ |
" |
# |
# |
# |
# |
# |
# |
# |
# |
# |
# |
" |
# |
sp |
cr |
| 54 |
41 |
43 |
2B |
47 |
4D |
3D |
53 |
2B |
22 |
|
|
|
|
|
|
|
|
|
|
22 |
|
20 |
0D |
Delay a few seconds to allow the modem to returns a few bytes
The plc sends the message mmmmmmmmmmmm followed by (ctrl z)
| 63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
| m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
^Z |
sp |
| m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
m |
sp |
^Z |
| |
|
|
|
|
|
|
|
|
|
|
|
20 |
1A |
The modem returns (CRLF) +CMGS:## (CRLF) (CRLF) OK (CRLF)
The SMS has been sent
PLC GENERAL PORT TRANSMISSION
- Setup the baud, bits, start and end code first
- Note that modem use only sends AT&F after power up
- The general port can be used by the ladder program
- To transmit via the port, first setup the message in data
- Note that data hi and lo bytes are swapped
- Then call the F144 transmit command
- F144 uses the first data specified, do not use for your message
- F144 sends the number of bytes/characters you specify
- Note that one data is two bytes/characters
- If an end code is setup this will be send automatically
- F144 then turns on the transmit end flag R9039
- It is now safe to transmit again
PLC GENERAL PORT RECEPTION
- Setup the reception area first
- The first data in the area is used as a reception byte counter
- The reception byte counter is cleared during each transmit
- The PLC reads the incomming bytes and stores them in PLC memory
- The PLC updates the reception counter
- If an end code is setup then the receive flag R9038 will turn on
- If the receive flag turns on it MUST be cleared
- No more data will be received until the receive flag is cleared
- The only way to clear the receive flag is to transmit
- To transmit without sending anything use byte count = zero
PLC PROGRAM EXAMPLE
Sequence
- R9013 pulses once during power up
- When the power turns on the plc waits for Timer zero
- Timer 0 is set at half a minute for the modem to warm up Timer 0 starts internal relay R51
- R51 moves an AT (CRLF) message into memory, sends it to the modem and sets R52
- R52 checks the length of the reply from the modem and sets R53 if ok
- if there is no answer times 1 times out and sets R51 again
- If external button, input X7 changes state and R53 then it sets R54
- R54 sets up the telephone number data and sends the message command to the mdem
- R55 waits for timer 2, this is to allow the modem time
- R56 sets up the message data and sends the message text
- R57 checks the length of the reply
- If there is no answer then timer 3 sets an error output
Inputs
- X7 is uses as a trigger to send a message
Outputs
- Y0 flashes for startup and is then on
- Y1 flashes during modem check and is then on
- Y2 flashes during message transmission
- Y5 flashes slowely if the message could not be sent
Timers
- T0 Startup delay
- T1 Modem check timeout
- T2 Delay between command and message
- T3 Message timeout
Internal Relays
- R50 procedure is running flag
- R51..R59 as above
- R5A message was not sent
Internal Data (16 bits)
- DT50..DT99 transmit buffer
- DT100..DT200 receive buffer
Files
INSAPP04.PDF Program printout
Rev 1.1 20041023 R.H |