Tip052B TOPIC: How to Use the XMT and RCV Instructions to... an Operator Interface VERSION: 4.0

INDUSTRIAL AUTOMATION
Tip052B
TOPIC: How to Use the XMT and RCV Instructions to Communicate with
an Operator Interface
VERSION: 4.0
DATE: 03/99
***SPECIAL HARDWARE REQUIREMENTS***
Operator Interface
This program uses the Terminal program that is shipped with
Windows 3.1 (called HyperTerminal in later versions of Windows).
The terminal program should be configured as follows:
DEC VT100 (ANSI)
Local Echo
9600, 7 bits, odd parity, 1 stop bit
Flow control -- none
Host
One S7-200 CPU
One PC/PPI cable. Attach one end to Port 0 of the CPU and the
other end to an RS-232 port of the PC.
The PC/PPI cable should be configured for 9600 baud.
***OVERVIEW***
This tip explains how to use the Transmit (XMT) and Receive (RCV)
instructions to communicate with an operator interface. The S7-200
program is executed on an S7-200 CPU that is connected to a PC by
means of a PC/PPI cable. The PC is executing a Terminal program.
The XMT instruction is used to transmit the command menu and error
information. The RCV instruction is used to receive the commands
from the Terminal program. This program supports two commands, ON
and OFF. If ON is entered, then the first 8 outputs on the S7-200
CPU are turned on. If OFF is executed, then the first 8 outputs
are turned off.
***PROGRAM STRUCTURE***
The program consists of the following routines:
Main
SBR0
SBR1
SBR2
SBR3
SBR4
SBR5
INT0
INT1
Initialize the program.
Initialize the Port 0 communication parameters.
Initialize the Port 0 Receive parameters.
Process the message that is received.
Transmit the command menu.
If the two-character delay time has elapsed,
indicate that the next Comm State is TRANSMIT
Transmit the first error that is found.
Set up to receive the next command.
Indicate that the Port 0 Receive Message is complete.
***PROGRAM DESCRIPTION***
The RCV Instruction
Special Memory Bits
SM4.5 - Port 0: This bit is turned on when the transmitter is idle
(Port 0). (0 = transmission in progress, 1 = transmitter is idle).
The symbol name is Xmit0_Idle.
SM4.6 - This bit is turned on when the transmitter is idle (Port 1).
(0 = transmission in progress, 1 = transmitter idle). The symbol
name is Xmit1_Idle.
Each time the RCV instruction is executed, the count field in the
designated Receive buffer is cleared. All other data in the buffer
will be overwritten as new data is received.
The PC/PPI cable contains a data-enabled RS-232 to RS-485 converter.
If you use this cable for Freeport communication, you should allow
a minimum of two character times between messages of opposite directions
(Receive versus Transmit). The calculations in the following table
are based on a 10-bit character (1 start bit, 7 data bits, 1 parity
bit, 1 stop bit). The table below gives character times for the
different baud rates.
Baud rate
38400
19200
9600
4800
2400
1200
600
1 Character Time 2 Character Times
(in Milliseconds) (in Milliseconds)
0.26
0.52
0.52
1.04
1.04
2.08
2.08
4.17
4.16
8.34
8.34
16.67
16.67
33.34
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
300
33.34
66.67
To calculate message time in milliseconds, use the following formulas:
Character_time = 1000 ms/(baud rate/number_of_bits_per_character)
Message_time = character_time * number_of_characters
If there is a change in the port configuration (that is, parity,
data bits, or baud rate), the RCV instruction will reset the port
and install the new configuration before setting up to receive
characters.
The execution of XMT and RCV instructions is mutually exclusive.
The following combinations of instructions produce an error if
executed simultaneously on the same port: XMT - XMT, RCV - RCV,
XMT - RCV, and RCV - XMT. In all cases, the first instruction will
be executed correctly and the second instruction will fail with a
non-fatal error (9).
You must specify at least one start condition and one stop condition
in order to execute the RCV instruction. Once the start-of-message
condition has been met, a message termination must occur before
another message can be received. A restart condition is not supported.
Start and End Conditions:
· Start_of_message: Idle_Line_Time-out AND Start_Character
· End_of_Message: End_Character OR Message/Character_Time-out
OR Max_Character_Count OR Parity_Error OR Disable_Command
To abort the RCV instruction that is being executed, clear bit n (7)
in the control byte for the Receive Message (SMB87 or SMB187,
Port 0 or Port 1, respectively) and then execute the RCV instruction
for the port in question. The previous RCV instruction will be
aborted and bit n (7) "Receive Message terminated by user disable
command" in the Receive Message byte (SMB86 or SMB186, Port 0 or
Port 1, respectively) will be set. To receive another message from
the port in question, it will be necessary to re-enable the RCV
function for that port by setting bit n (7) in the Receive Message
control byte and executing the RCV instruction for the specified port.
PORT 0
PORT 1
NAME (SYMBOL NAME)
USAGE
----------------------------------------------------------------------------SM4.5 Port 0 Transmitter Idle
Use this bit to determine if
(Xmit0_Idle)
the transmitter is busy.
SM4.6 Port 1 Transmitter Idle
Use this bit to prevent executing
(Xmit1_Idle)
two XMT instructions simultaneously
on the same port.
If two XMT instructions are
executed simultaneously
on the same port, a non-fatal
error occurs.
----------------------------------------------------------------------------SMB30
Freeport Mode Control
Set up protocol and port
Register
communication parameters.
SMB130
(P0_Config)
XMT and RCV can only be used
(P1_Config)
with the Freeport protocol.
----------------------------------------------------------------------------SMB86
Receive Message Status Use to determine which termination
SMB186
Byte (P0_Stat_Rcv)
condition terminated the RCV
(P1_ Stat_Rcv)
instruction.
MSB
LSB
7
0
n 0 e 0 0 t c p
----------------------------------------------------------------------------SMB87
Receive Message Control Used to configure the start and stop
SMB187
Byte
conditions for receiving a message.
(P0_ Ctrl_Rcv)
Also used to abort a message.
(P1_Ctrl_Rcv)
MSB
LSB
7
0
n x y z m t 0 0
----------------------------------------------------------------------------SM87.7
Enable/Disable Receive The RCV instruction can only operate
Function
if it is enabled.
SM187.7
(P0_ Ctrl_Rcv.7)
If the RCV instruction is in
operation and this bit is cleared
(disabled), the execution of the
next RCV instruction will terminate
(abort) the Receive function. This
termination will occur even if the
message is in the process of being
received.
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
----------------------------------------------------------------------------SM87.6
Detect Start of Message
Use the value in SMB88/SMB188 to
SM187.6
Character
detect the start of message.
[Start Condition]
This could be a character used to
(P0_ Ctrl_Rcv.6)
detect the start of message or
(P1_ Ctrl_Rcv.6)
possibly the address of your node
in a network (for example, if this
CPU is node 5, load a 5 into SMB88).
Any message that does not start with
a 5 will not be received.
----------------------------------------------------------------------------SM87.5
Detect End of Message
Use the value in SMB89/SMB189 to
SM187.5
Character
detect end of message. In an
[Message Termination]
application where you are entering
(P0_ Ctrl_Rcv.5)
data, the <carriage return>
(P1_ Ctrl_Rcv.5)
character might make a good
end-of-message character. Make sure
that you use another form of
termination such as inter-character
time-out or end-of-message time-out
just in case the end-of-message
character is not received.
------------------
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 1
Initialization
Load special memory bit SM0.1 to process this network in the first
scan cycle only.
Call subroutine SBR0 to initialize the Port 0 communication parameters.
Call subroutine SBR1 to initialize the Port 0 Receive parameters.
Attach interrupt event 9 (Port 0: Transmit complete) to interrupt
INT0 to enable INT0 when transmission is complete.
Attach interrupt event 23 (Port 0: Receive Message complete) to
INT1 to enable INT1 when reception is complete.
Enable all interrupt events.
Move the constant 0 into memory byte MB0 to clear the error byte.
Move the constant 0 into variable memory byte VB1 to initialize the
error sub-state to 0.
Move the constant 0 into variable memory byte VB0 to initialize the
Comm State to 0.
Transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB580, Command buffer - Enter command
(ON|OFF + <CR>).
SM0.1
0
1
0
9
1
23
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
MB0
INDUSTRIAL AUTOMATION
0
VB1
0
VB0
VB580
0
Network 2
Comm State RECEIVE
Compare the value in variable memory byte VB0 (Comm State)
to the constant 1 (1 = Comm State RECEIVE).
If the value in VB0 is equal to 1,
call SBR2 to process the received message.
VB0
2
1
Network 3
Comm State TRANSMIT
Compare the value in variable memory byte VB0 (Comm State)
to the constant 2 (2 = Comm State TRANSMIT).
If the value in VB0 is equal to 2,
call SBR3 to process the transmission.
VB0
3
2
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 4
Comm State WAIT
Compare the value in variable memory byte VB0 (Comm State)
to the constant 3 (3 = Comm State WAIT).
If the value in VB0 is equal to 3,
call SBR4 to process the two-character delay.
VB0
4
3
Network 5
Comm State ERROR
Compare the value in variable memory byte VB0 (Comm State)
to the constant 4 (4 = Comm State ERROR).
If the value in VB0 is equal to 4,
call SBR5 to process the error.
VB0
5
4
Network 6
Main Program End
Network 7
Subroutine SBR0
Start SBR0 to initialize the Port 0 communication parameters.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 8
Initialize the Port 0 Communication Parameters
Move the hexadecimal value E9 (binary 1110 1001) into special memory
byte SMB30 (Freeport control register for Port 0). This bit combination
configures the communication interface for Freeport mode, 9600 baud,
7 data bits per character, and odd parity.
16#E9
Network 9
SMB30
End of Subroutine SBR0.
End SBR0.
Network 10
Subroutine SBR1
Start SBR1 to initialize the Port 0 Receive parameters.
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 11
Initialize the Port 0 Receive Parameters
Start SBR1 to initialize the Receive parameters (Port 0).
Move the hexadecimal value B4 (binary 1011 0100) into special memory
byte SMB87 (the control byte for the Receive Message function of
Port 0) to achieve the following settings:
MSB
LSB
SMB87 7
0
n x y z m t 0 0
n: (1) Receive Message function is enabled.
x: (0) Ignore SMB88.
y: (1) Use the value of SMB89 to detect the end
of message.
z: (1) Use the value of SMW90 to detect an idle
line condition.
m: (0) The timer is an inter-character timer (SMW92).
t: (1) Terminate Receive if the time period in
SMW92 is exceeded. (m)
Move the hexadecimal value 0D (ASCII character for <Carriage return>
into special memory byte SMB89 to use <CR> as the end-of-message
character.
Move the constant 50 into special memory word SMW90 to indicate an
idle line time of 50 ms.
Move the constant 4000 into special memory word SMW92 to indicate
an inter-character timer time-out value of 4000 ms.
Move the constant 6 into special memory byte SMB94 to set the maximum
number of characters to be received = 6.
16#B4
SMB87
16#D
SMB89
+50
SMW90
+4000
SMW92
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
6
Network 12
SMB94
End of Subroutine SBR1
End SBR1.
Network 13
Subroutine SBR2
Start SBR2 to process the message that is received (Comm State 1,
RECEIVE).
This state processes valid messages.
This subroutine determines whether the command is supported or not.
Only 2 commands are supported:
"ON" = turn 8 outputs on
and "OFF" = turn 8 outputs off.
2
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 14
Process the Message ON
If the hexadecimal value 4F4E (ASCII characters "O" and "N")
are equal to the value in variable memory word VW641
(the first two characters of the Receive Message),
and the constant 3 is equal to the value in variable memory byte
VB640 (character count of the Receive buffer),
move the hexadecimal value FF (binary 1111 1111) into output byte
QB0 to turn on 8 outputs,
move the constant 3 into variable memory byte VB0
to indicate that the next Comm State is WAIT,
and jump to Label LBL0 to end SBR2.
16#4F4E
3
VW641
VB640
16#FF
QB0
3
VB0
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 15
Process the Message OFF
If the hexadecimal value 4F46 (ASCII characters "O" and "F")
are equal to the value in variable memory word VW641
(the first two characters of the Receive Message),
and if the hexadecimal value 46 (ASCII character "F")
is equal to the value in variable memory byte VB643
(the third character in the Receive Message),
and the constant 4 is equal to the value in variable memory byte
VB640 (character count of the Receive buffer),
move the constant 0 into output byte QB0 to turn off 8 outputs.
Move the constant 3 into variable memory byte VB0
to indicate a Comm State of WAIT,
and jump to Label LBL0 to end SBR2.
If any of the preceding conditions are not true,
move the hexadecimal value 81 (binary 1000 0001)
into memory byte MB0 (the error byte),
move the constant 4 into variable memory byte VB0
to indicate a Comm State of ERROR,
and move the constant 1 into VB1
to indicate an error sub-state of WAIT.
16#4F46
16#46
4
VW641
VB643
VB640
0
QB0
3
VB0
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
16#81
MB0
4
VB0
INDUSTRIAL AUTOMATION
1
Network 16
Label LBL0
This network is the destination for the Jump to Label 0 instruction
from Networks 14 and 15.
This network brings the program to the end of SBR2.
0
Network 17
End of Subroutine SBR2
End SBR2.
Network 18
Subroutine SBR3
Start SBR3 to transmit the command menu (Comm State 2, TRANSMIT).
3
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB1
INDUSTRIAL AUTOMATION
Network 19
If the Transmitter Is Not Busy, Transmit the Command Menu
Special memory bit SM4.5 is turned on when the transmitter at
Port 0 is idle.
Load SM4.5 as a Normally Open contact
and negate its status.
That is, if SM4.5 is off (has a signal state of 0, Port 0 is not
idle),
jump to Label 0 to end SBR3.
If SM4.5 is on (has a signal state of 1, Port 0 is idle),
move the constant 0 into memory byte MB0 to clear the error byte.
Transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB580 (the command buffer).
Move the constant 0 into variable memory byte VB0 to initialize
the Comm State to 0.
SM4.5
0
0
MB0
VB580
0
0
Network 20
Label LBL0
This network is the destination for the Jump to Label 0 instruction
from Network 19.
This network brings the program to the end of SBR3.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 21
End of Subroutine SBR3
End SBR3.
Network 22
Subroutine SBR4
Start SBR4 to advance the Comm State to TRANSMIT if the
two-character time delay has elapsed (Comm State 3, WAIT)
4
Network 23
If the Two-Character Time Delay Has Elapsed, Transmit
If T32 is on (that is, when the current value of the timer = the
Preset Time of 5 ms),
move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
T32
2
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 24
End of Subroutine SBR4
End SBR4.
Network 25
Subroutine SBR5
If an error occurred on the last Receive Message,
start SBR5 to transmit the first error that is found.
5
Network 26
If an Error Occurs, Transmit the First Error That Is Found
If an error occurred on the last Receive Message,
then the first error found is transmitted (Comm State 4, ERROR).
After the error has been transmitted, then the
next Comm State is TRANSMIT.
Note: VB1 only has meaning when the Comm State is ERROR
Compare the value in variable memory byte VB1 (error sub-state)
to the constant 1.
If VB1 is equal to 1, that is, if the error sub-state is WAIT,
and if T32 is on (that is, when the two-character time-out has expired),
move the constant 2 into VB1 to set the next error sub-state to TRANSMIT.
VB1
T32
1
2
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB1
INDUSTRIAL AUTOMATION
Network 27
Is Error Sub-State TRANSMIT?
Compare the value in variable memory byte VB1 (error sub-state)
to the constant 2.
If VB1 is not equal to 2 (that is, if the error sub-state is not
TRANSMIT),
jump to Label LBL0 to end SBR5.
VB1
0
2
Network 28
Receive Message Terminated: User Disable Command
If special memory bit SM86.7 is on (that is, if the Receive Message
has been terminated by a user disable command),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB100
(Receive Message terminated: user disable command).
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
Jump to Label LBL1 to end SBR5.
SM86.7
VB100
0
2
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 29
Receive Message Terminated: Timer Has Expired
If special memory bit SM86.2 is on (that is, if the Receive Message
has been terminated because the timer has expired),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB260
(Receive Message terminated: timer expired).
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
Jump to Label LBL1 to end SBR5.
SM86.2
VB260
0
2
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 30
Receive Message Terminated: Maximum Character Count Achieved
If special memory bit SM86.1 is on (that is, if the Receive Message
has been terminated because the maximum character count has been achieved),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB340
(Receive Message terminated: maximum character count achieved).
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
Jump to Label LBL1 to end SBR5.
SM86.1
VB340
0
2
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 31
Receive Message Terminated: Parity Error
If special memory bit SM86.0 is on (that is, if the Receive Message
has been terminated because a parity error occurred),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB420
(Receive Message terminated: parity error).
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
Jump to Label LBL1 to end SBR5.
SM86.0
VB420
0
2
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 32
Receive Message Terminated: Invalid Command
If memory bit M0.0 is on (that is, if there was an invalid command),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB500 (invalid command)
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
Jump to Label LBL1 to end SBR5.
M0.0
VB500
0
2
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
VB0
INDUSTRIAL AUTOMATION
Network 33
Receive Message Terminated: End Character Received
If special memory bit SM86.5 is on (that is, if the
end character has been received),
transmit by means of Port 0 the data buffer (TABLE) that starts
at variable memory byte VB180 (end character received).
Move the constant 2 into variable memory byte VB0 to indicate
that the next Comm State is TRANSMIT.
SM86.5
VB180
0
2
Network 34
VB0
Label LBL1
This network is the destination for the Jump to Label 1 instruction from Networks 28 through 32.
This network brings the program to the end of SBR5.
1
Network 35
Label LBL0
This network is the destination for the Jump to Label 0 instruction from Network 27.
This network brings the program to the end of SBR5.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 36
End of Subroutine SBR5
End SBR5.
Network 37
INTERRUPT Routine INT0
INT0 is the Port 0 Transmit Complete interrupt.
0
Network 38
Set Up to Receive the Next Command
Load memory bit M0.7 (the gross error bit) as a Normally Open contact
and negate it so that power will flow if M0.7 is not turned on
(has a signal state of 0).
If M0.7 is not turned on, store the message that is received
through Port 0 in the data buffer (TABLE) that starts at
variable memory byte VB640 (the Receive buffer).
M0.7
VB640
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 39
End of Interrupt Routine INT0
End INT0.
Network 40
Interrupt Routine INT1
Start INT1 as the routine that indicates Port 0 Receive Message is complete.
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 41
Check to See If an End Character Has Been Received
Compare the value in special memory byte SMB86
to the hexadecimal value 20 (binary 0010 0000).
If the values are equal, this means that an end character
has been received.
If an end character has not been received,
jump to Label LBL0 to indicate that an error has occurred.
If an end character has been received,
move the constant 1 into variable memory byte VB0
to indicate a Comm State of RECEIVE,
move the constant 0 into memory byte MB0
to clear the error byte,
and jump to Label LBL1
to reset the two-character delay timer
and set the character delay to 5 ms.
SMB86
0
16#20
1
Network 42
Label LBL0
This network is the destination for the Jump to Label 0 instruction
from Network 41.
The network that follows this label indicates that an error has occurred.
0
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
1
VB0
0
MB0
INDUSTRIAL AUTOMATION
Network 43
Indicate an Error
Load special memory bit SM0.0 to process this network every scan cycle.
Move the constant 4 into variable memory byte VB0
to indicate a Comm State of ERROR.
Move the constant 1 into VB1
to indicate an error sub-state of WAIT.
Move the hexadecimal value 80 (binary 1000 0000)
into memory byte MB0 to indicate that an error has occurred.
SM0.0
Network 44
4
VB0
1
VB1
16#80
MB0
Label LBL1
This network is the destination for the Jump to Label 1 instruction
from Network 41.
The network that follows this label resets the two-character delay timer
and sets the character delay to 5 ms.
1
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.
INDUSTRIAL AUTOMATION
Network 45
Reset the Delay Timer and Set the Character Delay to 5 ms.
Load special memory bit SM0.0 to process this network every scan cycle.
Reset the two-character delay timer T32
and enable timer T32, using the constant 5 as the Preset time (PT).
Timer T32 has a resolution of 1 ms, that is, each count of the current
value of timer T37 is a multiple of 1 ms. A Preset Time of 5 in this
case provides a time-out of 5 ms, the two-character delay.
SM0.0
T32
1
T32
+5
Network 46
End of Interrupt Routine INT1
End INT1.
PROLIFIC SYSTEM AND TECHNOLOGY PVT.LTD.