西门子培训教程手册合集s7net编程接口_第1页
西门子培训教程手册合集s7net编程接口_第2页
西门子培训教程手册合集s7net编程接口_第3页
西门子培训教程手册合集s7net编程接口_第4页
西门子培训教程手册合集s7net编程接口_第5页
已阅读5页,还剩219页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、SIMATIC NETS7 Program InterfaceVolume 1 of 11 The SAPI-S7 Interface2 Principles of the ProgramInterface3 The ProgramInterface4 Trace and Mini-DB5 Configuration6 SAPI-S7 Under MS-DOS/Windows7 Appendix Glossary IndexC79000-G8976-C077Release 6SIMATIC NET is a trademark of Siemens Siemens Aktiengesellsc

2、haftWir haben den Inha er Druckschrift auf berein- stimmung mit der beschriebenen Hard- und Software geprft. Dennoch knnen Abweichungen nicht ausge- schlossen werden, so da wir fr die vollstndige bereinstimmung keine Gewhr bernehmen. Die Angaben in der Druckschrift werden jedoch regelm- ig berprft.

3、Notwendige Korrekturen sind in den nachfolgenden Auflagen enthalten. Fr Verbesse- rungsvorschlge sind wir dankbar.Technische nderungen vorbehalten.We have checked the contents of this manual for agreement with the hardware described. Since deviations cannot be precluded entirely, we cannot guarantee

4、 full agreement. However, the data in this manual are reviewed regularly and any necessary corrections included in subsequent editions.Suggestions for improvement are welcome. Technical data subject to change.Nous avons vrifi la conformit du contenu du prsent manuel avec le matriel et le logiciel qu

5、i y sont dcrits. Or, des divergences ntant pas exclues, nous ne pouvons pas nous porter garants pour la conformit intgrale. Si lusage du manuel devait rvler des erreurs, nous en tiendrons compte et apporterons les corrections ncessaires ds la prochaine dition.Veuillez nous faire part de vos suggesti

6、ons.Nous nous rservons le droit de modifier les caractristiques techniques.Weitergabe sowie Vervielfltigung dieser Unterlage, Verwertung und Mitteilung ihres Inhalts nicht gestattet, soweit nicht ausdrcklich zugestanden. Zuwiderhand- lungen verpflichten zu Schadenersatz. Alle Rechte vorbehalten, ins

7、besondere fr den Fall der Patentertei- lung oder GM-Eintragung.C79000-G8976-C077Copyright Siemens AG 1995 to 1999The reproduction, transmission or use of this document or its contents is not permitted without express written authority. Offenders will be liable for damages. s, including rights create

8、d by patent grant or registration of a utility or design, are .C79000-G8976-C077Copyright Siemens AG 1995 to 1999Toute communication ou reproduction de ce support dinformations, toute exploitation ou communication de son contenu sont interdites, sauf autorisation expresse. Tout manquement cette rgle

9、 est illicite et expose son auteur au versement de dommages et intrts.Tous nos droits sont rservs, notamment pour le cas de la dlivrance dun brevet ou celui de lenregistrement dun modle dutilit.C79000-G8976-C077Copyright Siemens AG 1995 1999Siemens AktiengesellschaftElektronikwerk KarlsruhePrinted i

10、n the Federal Republic of GermanySIMATIC NETS7 Program InterfaceDescriptionC79000-B8976-C077/063NoteWe would point out that the contents of this product documentation shall not become a part of or modify any prior or existing agreement, commitment or legal relationship. The Purchase Agreement contai

11、ns the complete and exclusive obligations of Siemens. Any statements contained in this documentation do not create new warres or restrict the existing warranty.We would further point out that, for reasons of clarity, these operating instructions cannot deal with every possible problem arising from t

12、he use of this device. Should you require further information or if any special problems arise which are not sufficiently dealt with in the operating instructions, please contact your local Siemens representative.GeneralThis device is electrically operated. In operation, certain parts of this device

13、 carry a dangerously high voltage.WARNING !Failure to heed warnings may result in serious physical injury and/or material damage.Only appropriately qualifiednel may operate this equipment or work in its vici. nel must be familiar with all warnings and maintenance measures in accordance with these op

14、erating instructions.Correct and safe operation of this equipment requires proper transport, storage and assembly as well as careful operator control and maintenance.nel qualification requirementsQualifiednel as referred to in the operating instructions or in the warning notes are defined ass who ar

15、e familiar with the installation, assembly, startup and operation of this product and who possess the relevant qualifications for their work, e.g.: Training in or authorization for connecting up, grounding or labeling circuits and devices or systems in accordance with current standards in safety tec

16、hnology; Training in or authorization for the maintenance and use of suitable safety equipment in accordance with current standards in safety technology; First Aid qualification.B89077/06S7 ProgramInterfaceS7 Program InterfaceSIMATIC S7 system components communicate with each other using the S7 comm

17、unications protocol. To allow program device/PC application programs access to SIMATIC S7 system components, the SAPI-S7 program interface was developed. With its C program inter- face, you have flexible and simple access to the data of SIMATIC S7 system components.This volume describes the S7 proto

18、col and how to program it.223Notes1 The SAPI-S7 Interface111.1 Advantages of S7 Compared With Other Protocols121.2 Advantages of the SAPI-S7 Program Interface132 Principles of the Program Interface152.1 Synchronous and Asynchronous Job Handling162.2 Advantages of Asynchronous Operation172.3 Receive

19、Call and Processing Functions182.4 Handling S7 Connection Management Services202.5 Error Message Concept212.6 The Trace222.7 The Mini-DB.232.8 Multi-CP and Multi-User Operation.242.8.1 Assigning VFDs and the S7 Connection List252.9 Installation and Requirements for Operation263 The Program Interface

20、273.1 Overview of the Program Interface283.1.1 Administrative Services293.1.2 Receive Service.303.1.3 S7 Connection Management Services303.1.4 Variable Services323.1.5 Block-Oriented Services353.1.6 Message Services363.1.7 VFD Services373.1.8 Diagnostic Services for Fault-Tolerant Connections383.2 A

21、dministrative Services393.2.1 s7_get_device433.2.2 s7_get_vfd453.2.3 s7_init473.2.4 s7_get_cref493.2.5 s7_get_conn503.2.6 s7_shut523.3 Receive service533.3.1 s7_receive553.4 S7 connection management services583.4.1 s7_initiate_req633.4.2 s7_get_initiate_cnf643.4.3 s7_await_initiate_req653.4.4 s7_get

22、_await_initiate_cnf663.4.5 s7_get_initiate_ind673.4.6 s7_initiate_rsp683.4.7 s7_abort703.4.8 s7_get_abort_ind713.5 Variable Services723.5.1 s7_req793.5.2 s7_get_ _cnf813.5.3 s7_write_req833.5.4 s7_write_long_req863.5.5 s7_get_write_cnf893.5.6 s7_multiple_req903.5.7 s7_get_multiple_cnf933.5.8 s7_mult

23、iple_write_req963.5.9 s7_get_multiple_write_cnf993.5.10 s7_cycl_init_req1013.5.11 s7_get_cycl_init_cnf1043.5.12 s7_cycl_start_req1053.5.13 s7_get_cycl_start_cnf1063.5.14 s7_get_cycl_ind1073.5.15 s7_get_cycl_abort_ind1093.5.16 s7_cycl_stop_req1103.5.17 s7_get_cycl_stop_cnf1113.5.18 s7_cycl_delete_req

24、1123.5.19 s7_get_cycl_delete_cnf1133.5.20 s7_cycl_1143.6 Block-Oriented Services1173.6.1 s7_bsend_req1233.6.2 s7_get_bsend_cnf1253.6.3 s7_brcv_init1263.6.4 s7_get_brcv_ind.1283.6.5 s7_brcv_stop1303.7 Message Services1313.7.1 s7_msg_initiate_req1353.7.2 s7_get_msg_initiate_cnf1363.7.3 s7_msg_abort_re

25、q1373.7.4 s7_get_msg_abort_cnf1383.7.5 s7_get_scan_ind1393.7.6 s7_get_alarm_ind1463.8 VFD Services.1523.8.1 s7_vfd_state_req1553.8.2 s7_get_vfd_state_cnf1563.9 Diagnostic Services for Fault-Tolerant Connections1583.9.1 s7_diag_init.1603.9.2 s7_get_diag_ind1613.9.3 s7_diag_stop1634 Trace and Mini-DB1

26、654.1 s7_trace1664.2 s7_write_trace_buffer.1674.3 s7_mini_db_set1684.4 s7_mini_db_get1744.5 s7_last_iec_err_no1764.6 s7_last_iec_err_msg1784.7 s7_last_ ed_err_no1794.8 s7_last_ ed_err_msg1834.9 s7_discard_msg1845 Configuration1855.1 Significance of Configuration1865.2 Services With Configuration Dat

27、a1875.3 Configuring with STEP 7 V51886 SAPI-S7 Under MS-DOS/Windows1896.1 General Information1906.2 Translating and Linking for MS-DOS1926.3 Translating and Linking for Windows 3.x1946.4 Translating and Linking for Windows 95 and Windows NT1976.5 Environment Variables1986.6 The Trace for MS-DOS or W

28、indows2006.7 Special Features for Windows.2016.7.1 s7_set_window_handle_msg2027 Appendix2037.1 Range of Functions of SAPI-S72047.2 Special Notes.2067.3 Formulas for Calculating Data Lengths for the Variable Services2077.4 Representation of S7 Variables2097.5 Representation of the Standard Data Types

29、2107.5.1 Representation of the Boolean Data Type2107.5.2 Representation of the Data Type Integer.2117.5.3 Representation of the Unsigned Data Type2147.5.4 Representation of the Floating Point Data Type2167.5.5 Representation of the Visible String Data Type2187.5.6 Representation of the Octet String

30、Data Type2197.5.7 Representation of the Bit String Data Type220Glossary221Index2231 The SAPI-S7 InterfaceThis chapter explains the advantages of the S7 communications protocol comparedwith other protocols and the S7 program (SAPI-S7).interface for PC/programdevices1.1 Advantages of S7 Compared With

31、Other ProtocolsAdvantages of S7The advantages of S7 compared with other protocols are as follows: Low load on the processor and bus.The S7 protocol is optimized for SIMATIC communication. SimplicityThe S7 protocol elements aapted to the requirements of SIMATIC and are therefore simple to use. SpeedC

32、ompared with other layer 7 automation protocols, such as MMS, S7 provides a high performance. Compatibility.Fail-safe communication with S7 H systems with the same pro- gram interface as to the standard SIMATIC S7 systems.1.2 Advantages of the SAPI-S7 Program InterfaceWhat Does SAPI- S7 Mean?What is

33、 SAPI-S7?The acronym SAPI-S7 stands for the following: SAPI - Simple Application Programmers Interface, S7 - the layer 7 communications protocol of SIMATIC S7 sy- stems.SAPI-S7 is a simple C program interface, provides access to the S7 services on PCs and PGs and is available as a C library and is o

34、perated with Siemens drivers and communications processors.Advantages of the SAPI-S7 Pro-gram InterfaceThe SAPI-S7 program interface has the following advantages: SAPI-S7 is a simple but nevertheless flexible and high- performance interface that requires only one transferred parame- ter field per jo

35、b and allows simple buffer management. SAPI-S7 is easy to learn. The SAPI-S7 program interface is designed for asynchro- nous operation since asynchronous calls are more efficient (more jobs can be processed at the same time). It allows status messages to be received at any time and is ideally suite

36、d for creating event-driven programs, for example under Windows. SAPI-S7 handles sequential services automatically, such as active or passive connection establishment that consists of se- veral individual steps. The user does not need to worry about sequences and error handling in the individual ste

37、ps. Writing a program is therefore much simpler. SAPI-S7 supports troubleshooting with an integrated trace function that writes the most important transfer parameters and return values to a file. The trace can be activated and deactiva- ted for each individual service class. The SAPI-S7 program inte

38、rface is compatible with other SAPI program interfaces, in other words porting SAPI-S7 applications to applications of other SAPI program inter- faces (for example SAPI-FMS) requires little effort. The structures of the SAPI-S7 program interface are de- signed so that user programs translated with b

39、yte or word align- ment can access the individual components without problems. Consistent configuration of SIMATIC S7 and SAPI-S7 from STEP 7 V5 and higher. Diagnostic interface for fail-safe communication so that the application is informed at all times of the state of the redundant connection.2 Pr

40、inciples of the Program InterfaceThis chapter introduces you to the principles of the SAPI-S7 program follows:interface, as Implementation of asynchronous calls for improved performance and the creation of event-driven applications. Separation of receive calls and event-specific processing functions

41、 to simplify the SAPI-S7 programinterface. Library-internal processing of sequential services to simplify the user programs. Introduction of a logon and logoff function allowing multi-CP and multi-user ope- ration. Implementation of a trace for debugging the program and to allow the functions of the

42、 library and user programs to be checked.When you have worked through this chapter, you will be familiar with the principles of the S7 program interface and will be in a position to understand the interface for creating programs.2.1 Synchronous and Asynchronous Job HandlingSynchronous Job HandlingWh

43、en jobs aandled synchronously (Figure 2.1), the user program is blocked from the time of the request to the reception of the confirmati- on. Events occurring in the mecan only be processed if the program is interrupt-driven. This mode is not implemented in SAPI-S7.Communication systemServer1. Call2.

44、 Program waits3. Resume programrequestconfirmationindicationresponseFigure 2.1: Synchronous OperationAsynchronous Job HandlingIn asynchronous job handling (Figure 2.2) a user program is not blok- ked following a request and can receive any event and react to it. The confirmation is fetched explicitl

45、y with a receive call.Communication systemServer1. Callrequest2. Continue program3. Receive call4. Continue programconfirmationindicationresponseFigure 2.2: Asynchronous Operation2.2 Advantages of Asynchronous OperationAsynchronous Jobs as a Basic Principle of the SAPI-S7 Pro-gram InterfaceThe SAPI-

46、S7 program interface is designed for asynchronous operation. Asynchronous calls allow a higher data throughput (several jobs can be processed at the same time). An application is not blocked and isfor other tasks such as receiving status messages. Asynchronous mechanisms are ideal for creating event

47、-driven programs, for example under Windows.From the point of view of the application, you must decide whether or not the services used are dependent on each other. If they are interde- pendent, the execution of a job must be confirmed before the next job can be sent. For example, a connection must

48、be established before data can be transferred on the connection.2.3 Receive Call and Processing FunctionsHow is a Received Message Proces- sed?A message received from the lower protocol layers is processed by the user program in the two following steps (Figure 2.3): The s7_receive() function first f

49、etches an existing message. The return value provides information about the received event. Per event, a consts defined in the header file SAPI_S7.H, such as S7_INITIATE_IND that shows that the partner station wants to establish an S7 connection. If S7_NO_MSG is entered, no message was received. In

50、the next step, the user must call the appropriate processing function for the received message: an event identified by S7_INITIATE_IND requires the processing function s7_get_initiate_ind() to be called.Using the receive function, the application program can poll an event. However, between the recep

51、tion of the event and calling the proces- sing function, no further event can be fetched from the communicati- ons system.User programSAPI-S7Remote partnerInitiate connections7_receive()= S7_INITIATE_INDs7_get_initiate_ind()Process indication= S7_OKFigure 2.3: Receiving and Processing MessagesAdvant

52、ages of Separating the Receive Call and Processing FunctionSeparating the event processing into a receive function and an event- specific processing function achieves the following: Allows a simpler and clearer program interface. Only the data and parameters relevant to the received event are transf

53、er- red to the processing functions. Allows the SAPI-S7 program interface to be extended by additional events by making appropriate processing functions available. Separates the indication (receive call) and response (processing function). This allows user data to be prepared for the response.2.4 Ha

54、ndling S7 Connection Management ServicesSupport by the S7 LibraryThe SAPI-S7 library supports you during active and passive connection establishment that consists of several individual steps. Each step is checked for success or failure. If an error occurs, the library makes sure that steps that have al y been executed are corrected. After sending a request, you only need to call the receive function repeatedly until the confirmation of completion is received (see Figure 2.4).User programSAPI-S7Remote partnerIn

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论