PLC论坛-全力打造可编程控制器专业技术论坛

 找回密码
 注册哦

QQ登录

只需一步,快速开始

微信扫码登录

查看: 247|回复: 0

[西门子] How to Use the XMT and RCV Instructions

[复制链接]
发表于 2008-4-24 09:23:00 | 显示全部楼层

How to Use the XMT and RCV Instructions

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

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册哦

本版积分规则

QQ|小黑屋|手机版|Archiver|PLC技术网-PLC论坛 ( 粤ICP备17165530号 )|网站地图

GMT+8, 2024-9-20 05:41 , Processed in 0.042799 second(s), 23 queries .

快速回复 返回顶部 返回列表