Tip035B TOPIC: Connection between S7-200 and PC: How to Read... VERSION: 4.0 DATE: 5/99

INDUSTRIAL AUTOMATION
Tip035B
TOPIC: Connection between S7-200 and PC: How to Read from a Windows Application
VERSION: 4.0
DATE: 5/99
***SPECIAL SOFTWARE REQUIREMENTS***
SoftwareWedge for Windows: Professional Edition
Part # SW30WP (16 bit), SW3032P (32 bit), or other compatible software
Any Windows package that supports the DDE link
***OVERVIEW***
This programming example uses third-party software to read data
from a SIMATIC S7-200 series CPU to a Windows application. A simple
pumping system is simulated with the data being sent to different
cells in Microsoft Excel.
***PROGRAM DESCRIPTION***
Some software packages such as SoftwareWedge for Windows can interface
with the SIMATIC S7-200 CPU with a program running under Windows.
This means that information from an S7-200 CPU can be displayed in
any Windows application, and information can also be written to
the CPU from any Windows application.
Currently, SoftwareWedge does not permit information transmitted
from different inputs at different times to be displayed and updated
on different parts of the screen. However, different parts of a
given transmission from the S7-200 may be displayed at different
locations. Each part must be displayed in its own field in
SoftwareWedge. Each field is separated by a certain delimiting
character transmitted with the rest of the message. This character
may be any the user desires. Also, the end of every transmission
must have one or more "ending" characters, which the user may also
specify.
After loading the SoftwareWedge package, select the dynamic data
exchange (DDE) server mode and specify the DDE application name,
topic, and item as applicable. Then adjust the settings under the
Port list to a 9600 baud rate, no parity, 8 bits per character,
and 1 stop bit. Remember to set the communication port number as
well. Finally, you must define the record structures that will be
input. For the following program, start the record event with any
character received, end with a carriage return and a line feed,
select multiple delimited data fields, and enter three as the
maximum number of fields with a colon (: ASCII 58) as the
delimiting character. Finally, under the Windows application, use
a copy/paste link command to paste the different data fields to
the desired parts of the screen.
Optional: SoftwareWedge provides a way to automatically change
the format of a variable before it is passed to another Windows
application.
This program is an example of how an S7-200 series CPU might transmit
information to any Windows product using the appropriate software
(see above).
In this example, a simple program for a pumping system is given.
Assume input bit I0.0 turns on the main pump. Then input bit I0.1
opens or closes an emergency valve. Input bit I0.2 opens and closes
the main valve that begins the flow of liquid.
An operator sitting at a computer wants to see a message as each
of the three loads change. When input bit I0.0 is switched on, a
static message will appear: "Pump 1 is on". The state of input bit
I0.1 controls a message that is toggled back and forth: either
"Valve open" or "Valve closed". When input bit I0.2 is switched on,
it triggers a display of the flow time for the liquid. This message
changes every second that input bit I0.2 is switched on.
This program does not allow for all information at once, but only
as the status of each input bit changes according to the status
of the associated switch. A few changes to the program can be made,
however, to allow for the display of all information at once.
This would require the transmission of ALL data (even that
which has not changed) every time a new transmission is made. The
field delimiting character in this program is a colon (:), and the
transmission end characters are a carriage return followed by a line
feed.
This program writes several different kinds of information to the
Windows application. A static message, "Pump 1 is on", a message
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
with one varying word, "Valve is open/closed", and a constantly
changing input both as an integer and Hex value "Flow time (in sec)
####" are all included to provide a diverse range of sample messages.
The following table shows which variable memory values are used during
the program.
VW10
Main counting memory that displays number of seconds
of flow
VW20
Secondary counting memory - a copy of VW10 that
is used to allow the integer to binary-coded-decimal
conversion in subroutine SBR3 without erasing the
stored value in the counter
VB80
Stores the number 14, or the number of letters
stored as hexadecimal values in the table. Used
as a prerequisite to the XMT command.
VD81 - VW93 Message: "Pump 1 is on"
VB100
Stores either number 12 or 14 depending on state
of valve.
Describes number of hexadecimal values in the table
VD101 - VD109
Message: "Valve open" or "Valve closed"
or
VD101 - VW113
VB120
Stores the number 28, or number of hexadecimal
values in the following table
VD121 - VD133
Message: "Flow time in sec"
VB137
Stores a colon as a hexadecimal value to allow
for split in field
VB138 - VB141Stores value of second counter as ASCII value
that is displayed in Windows as an integer value
VB142
Colon as hexadecimal value for next field division
VB143 - VB146Stores value of second counter as ASCII for display
in Windows as a hexadecimal value
VW147
Carriage return, line feed - end of transmission
message
***MAIN PROGRAM***
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 1
Call Subroutine SBR0
Load special memory bit SM0.1 to process this network in the first
scan cycle only.
Call SBR0.
SM0.1
Network 2
0
If the Pump Switch Is On, Call Subroutine SBR1
Load input bit I0.0 to monitor the status of the pump switch.
If there is an off-to-on transition (Edge Up) at input bit I0.0,
call SBR1.
I0.0
Network 3
1
When Flow Starts, Move 0 to Timer Value
Load input bit I0.2 to monitor the status of the liquid flow.
If there is an off-to-on transition (Edge Up) at input bit I0.2,
move the constant 0 to VW10 to clear the main counting memory area.
I0.2
+0
Network 4
VW10
Call Subroutine SBR2.
Load input bits I0.2, I0.0, and I0.1 to check the status of the
switches.
If the liquid is flowing (input I0.2 is on)
and the pump is on (input I0.0 is on)
and the emergency valve is open (input I0.1 is on,)
call SBR2.
I0.2
I0.0
I0.1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
2
INDUSTRIAL AUTOMATION
Network 5
End of Main Program
End the main program.
Network 6
Subroutine SBR0
Start SBR0.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 7
Initialize
Load special memory bit SM0.0 to process this network every scan cycle.
Move the constant 9 (binary value 1001) into special memory byte
SMB30 to select Freeport protocol, 9600 baud, 8 bits per character,
and no parity.
Attach interrupt routine INT0 to interrupt event 2 to trigger INT0
every time there is an off-to-on transition at input bit I0.1.
Attach interrupt routine INT1 to interrupt event 3 to trigger INT1
every time there is an on-to-off transition at input bit I0.1.
Enable all interrupts.
SM0.0
9
SMB30
0
2
1
3
Network 8
End of Subroutine SBR0
End SBR0.
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 9
Subroutine SBR1
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 10
Write "Pump 1 is on"
Load special memory bit SM0.0 to process this network every scan cycle.
Move the constant 14 to variable memory byte VB80 to load the
length of this message into the table.
Move the hexadecimal value 50756D70 into variable memory double word
VD81 and
move the hexadecimal value 20312069 into variable memory double word
VD85 and
move the hexadecimal value 73206F6E into variable memory double word
VD89 to create the message "Pump 1 is on."
Move the hexadecimal value D0A into variable memory word VW93 to
place a carriage return and line feed at the end of the message.
Transmit the message buffer starting at VB80 to display the message.
SM0.0
14
VB80
16#50756D70
VD81
16#20312069
VD85
16#73206F6E
VD89
16#D0A
VW93
VB80
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 11
End of Subroutine SBR1
End SBR1.
Network 12
Subroutine SBR2
Start SBR2.
2
Network 13
Load Timer T32
When I0.2 is activated, T32 (an on-delay timer with a 1-ms resolution)
is loaded with a preset value of 1000, or 1 second.
SM0.0
T32
+1000
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 14
Transmit Message and Reset Timer T32
Load timer T32.
When T32 times out after 1 s,
move the constant 28 to variable memory byte VB120 to load 28
values into the table.
Move the appropriate hexadecimal values into the variable memory area
starting at VD121 to create the message "Flow time in sec"
Move the hexadecimal value 3A into VB137 and into VB142 to create
a colon (:) as a field delimiter.
Move the hexadecimal value D0A into variable memory word VW147 to
place a carriage return and line feed at the end of the message.
Increment variable memory word VW10 by 1 to increase the flow time
value.
Copy the new value into variable memory word VW20.
Convert the integer value in variable memory word VW20 to
a binary-coded decimal value.
Convert the BCD value in VB20 to an ASCII value for numerical display
and move the value to the table for transmission.
Convert the hexadecimal value in VB10 to an ASCII value for numerical
display and move the value to the table for transmission.
The table that begins at VB120 is updated every second (as timed by
T32) to read "Flow time in sec (Integer Value) (Hex Value)".
T32
28
VB120
16#466C6F77
VD121
16#2074696D
VD125
16#6520696E
VD129
16#20736563
VD133
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
16#3A
VB137
16#3A
VB142
16#D0A
VW147
VW10
VW10
VW10
VW20
VB20
4
VB138
VB10
4
VB143
VB120
0
+0
T32
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 15
Test for High Value
A test is placed at the end of the subroutine to reset VW10 if it
ever reaches the value 9999. This is done because the BCDI instruction
only allows a word (or 4 hexadecimal values) to be translated. If a
hexadecimal value is desired, then any number of digits can be converted.
VW10
+9999
+0
Network 16
VW10
End of Subroutine SBR2
End SBR2.
Network 17
Interrupt INT0
Start INT0.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 18
Transmit Message "Valve open"
Interrupt routine INT0 is triggered by an off-to-on transition at
input bit I0.1. Thus, the valve message is updated only when the
valve status changes. The message that is transmitted reads
"Valve open".
Load input bit I0.0. If input bit I0.0 is on,
move 12 values into the table starting at variable memory byte VB100.
Move the appropriate hexadecimal values into the table to produce
the message "Valve:open" The ":" is a field delimiter.
Place a carriage return and line feed at the end of the message.
Transmit the table beginning at VB100 for display.
I0.0
12
VB100
16#56616C76
VD101
16#653A6F70
VD105
16#656E0D0A
VD109
VB100
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 19
End of Interrupt INT0
End INT0.
Network 20
Interrupt INT1
Start INT1.
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 21
Transmit Message "Valve closed"
Interrupt routine INT0 is triggered by an on-to-off transition at
input bit I0.1. Thus, the valve message is updated only when the
valve status changes. The message that is transmitted reads
"Valve closed".
Load input bit I0.0. If input bit I0.0 is on,
move 14 values into the table starting at variable memory byte VB100.
Move the appropriate hexadecimal values into the table to produce
the message "Valve closed."
Move the hexadecimal value D0A into variable memory word VW113 to
place a carriage return and line feed at the end of the message.
Transmit the table beginning at VB100 for display.
I0.0
14
VB100
16#56616C76
VD101
16#653A636C
VD105
16#6F736564
VD109
16#D0A
VW113
VB100
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 22
End of Interrupt INT1
End INT1.
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.