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.
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.
The Program
This program communicates with an operator interface by using the transmit (XMT) and Receive (RCV) instructions. A state machine was implemented to perform the communications. The state machine consists of five communication states (Comm States):
- IDLE (0)
- RECEIVE (1)
- TRANSMIT (2)
- WAIT (3)
- ERROR (4)
Refer to the figure below for graphical representation of how the state machine works.
During the first scan cycle, port parameters are initialized, the XMT Complete event is attached to interrupt INT0, the RCV Complete event is attached to interrupt INT1, interrupts are enabled, the machine is initialized to IDLE, and the user menu is transmitted to the operator interface. When a Transmit Complete interrupt occurs, the RCV instruction is executed, unless the state machine is in the ERROR state. If the state machine is in the ERROR state, a Return from Interrupt is performed. Because the XMT and RCV instructions cannot be executed simultaneously, execution of the RCV instruction must be prevented until the command menu has been transmitted. Only error messages are transmitted in the ERROR state. However, an error message will always be followed by the command menu. If the RCV instruction were to be executed while the state machine is in the ERROR state, the command menu would not be transmitted because the XMT and RCV instructions cannot be executed simultaneously. The RCV instruction would take priority because it would have been executed first and the command menu would never be transmitted.
Normal operation of the state machine is as follows:
- The command menu is transmitted out.
- A Transmit Complete interrupt occurs.
- The Receive function is enabled.
- The state machine makes the transition to the IDLE state, waiting for a command to be received.
- A command is received.
- A Receive Complete interrupt occurs.
- A message check for Receive errors takes place.
- A state machine transition to the Receive state takes place.
- A message check for supported command takes place.
- The command is performed.
- The state machine makes the transition to the Transmit state.
- A command menu is transmitted.
Note: Comm State 3 "Two-character time wait" (WAIT) is only needed if you are using a PC/PPI cable. The two-character time wait is needed to turn the link around. If you are using a straight-through RS-485 cable, you can omit Comm State 3.
Project Example:tip052b.rar
|