logo资料库

西门子S7通讯协议API.pdf

第1页 / 共224页
第2页 / 共224页
第3页 / 共224页
第4页 / 共224页
第5页 / 共224页
第6页 / 共224页
第7页 / 共224页
第8页 / 共224页
资料共224页,剩余部分请下载后查看
SIMATIC NET - S7 Programming Interface
S7 Programming Interface
Contents
1 The SAPI-S7 Interface
1.1 Advantages of S7 Compared With Other Protocols
1.2 Advantages of the SAPI-S7 Programming Interface
2 Principles of the Programming Interface
2.1 Synchronous and Asynchronous Job Handling
2.2 Advantages of Asynchronous Operation
2.3 Receive Call and Processing Functions
2.4 Handling S7 Connection Management Services
2.5 Error Message Concept
2.6 The Trace
2.7 The Mini-DB
2.8 Multi-CP and Multi-User Operation
2.8.1 Assigning VFDs and the S7 Connection List
2.9 Installation and Requirements for Operation
3 The Programming Interface
3.1 Overview of the Programming Interface
3.1.1 Administrative Services
3.1.2 Receive Service
3.1.3 S7 Connection Management Services
3.1.4 Variable Services
3.1.5 Block-Oriented Services
3.1.6 Message Services
3.1.7 VFD Services
3.1.8 Diagnostic Services for Fault-Tolerant Connections
3.2 Administrative Services
3.2.1 s7_get_device
3.2.2 s7_get_vfd
3.2.3 s7_init
3.2.4 s7_get_cref
3.2.5 s7_get_conn
3.2.6 s7_shut
3.3 Receive service
3.3.1 s7_receive
3.4 S7 connection management services
3.4.1 s7_initiate_req
3.4.2 s7_get_initiate_cnf
3.4.3 s7_await_initiate_req
3.4.4 s7_get_await_initiate_cnf
3.4.5 s7_get_initiate_ind
3.4.6 s7_initiate_rsp
3.4.7 s7_abort
3.4.8 s7_get_abort_ind
3.5 Variable Services
3.5.1 s7_read_req
3.5.2 s7_get_read_cnf
3.5.3 s7_write_req
3.5.4 s7_write_long_req
3.5.5 s7_get_write_cnf
3.5.6 s7_multiple_read_req
3.5.7 s7_get_multiple_read_cnf
3.5.8 s7_multiple_write_req
3.5.9 s7_get_multiple_write_cnf
3.5.10 s7_cycl_read_init_req
3.5.11 s7_get_cycl_read_init_cnf
3.5.12 s7_cycl_read_start_req
3.5.13 s7_get_cycl_read_start_cnf
3.5.14 s7_get_cycl_read_ind
3.5.15 s7_get_cycl_read_abort_ind
3.5.16 s7_cycl_read_stop_req
3.5.17 s7_get_cycl_read_stop_cnf
3.5.18 s7_cycl_read_delete_req
3.5.19 s7_get_cycl_read_delete_cnf
3.5.20 s7_cycl_read
3.6 Block-Oriented Services
3.6.1 s7_bsend_req
3.6.2 s7_get_bsend_cnf
3.6.3 s7_brcv_init
3.6.4 s7_get_brcv_ind
3.6.5 s7_brcv_stop
3.7 Message Services
operating system
3.7.1 s7_msg_initiate_req
3.7.2 s7_get_msg_initiate_cnf
3.7.3 s7_msg_abort_req
3.7.4 s7_get_msg_abort_cnf
3.7.5 s7_get_scan_ind
3.7.6 s7_get_alarm_ind
3.8 VFD Services
3.8.1 s7_vfd_state_req
3.8.2 s7_get_vfd_state_cnf
3.9 Diagnostic Services for Fault-Tolerant Connections
3.9.1 s7_diag_init
3.9.2 s7_get_diag_ind
3.9.3 s7_diag_stop
4 Trace and Mini-DB
4.1 s7_trace
4.2 s7_write_trace_buffer
4.3 s7_mini_db_set
4.4 s7_mini_db_get
4.5 s7_last_iec_err_no
4.6 s7_last_iec_err_msg
4.7 s7_last_detailed_err_no
4.8 s7_last_detailed_err_msg
4.9 s7_discard_msg
5 Configuration
5.1 Significance of Configuration
5.2 Services With Configuration Data
5.3 Configuring with STEP 7 V5
6 SAPI-S7 Under MS-DOS/Windows
6.1 General Information
6.2 Translating and Linking for MS-DOS
6.3 Translating and Linking for Windows 3.x
6.4 Translating and Linking for Windows 95 and Windows NT
6.5 Environment Variables
6.6 The Trace for MS-DOS or Windows
6.7 Special Features for Windows
6.7.1 s7_set_window_handle_msg
7 Appendix
7.1 Range of Functions of SAPI-S7
7.2 Special Notes
7.3 Formulas for Calculating Data Lengths for the Variable Services
7.4 Representation of S7 Variables
7.5 Representation of the Standard Data Types
7.5.1 Representation of the 'Boolean' Data Type
7.5.2 Representation of the Data Type 'Integer'
7.5.3 Representation of the 'Unsigned' Data Type
7.5.4 Representation of the 'Floating Point' Data Type
7.5.5 Representation of the 'Visible String' Data Type
7.5.6 Representation of the 'Octet String' Data Type
7.5.7 Representation of the 'Bit String' Data Type
Glossary
Index
SIMATIC NET S7 Programming Interface Volume 1 of 1 1 The SAPI-S7 Interface 2 Principles of the Programming Interface 3 The Programming Interface 4 Trace and Mini-DB 5 Configuration 6 SAPI-S7 Under MS-DOS/Windows 7 Appendix Glossary Index C79000-G8976-C077 Release 7 SIMATIC NET is a trademark of Siemens Siemens Aktiengesellschaft
Wir haben den Inhalt der Druckschrift auf Übereinstimmung mit der beschriebenen Hard- und Software geprüft. Dennoch können Abweichungen nicht ausgeschlossen werden, so daß wir für die vollständige Übereinstimmung keine Gewähr übernehmen. Die Angaben in der Druckschrift werden jedoch regelmäßig überprüft. Notwendige Korrekturen sind in den nachfolgenden Auflagen enthalten. Für Verbesserungsvorschläge sind wir dankbar. Technische Änderungen vorbehalten. Weitergabe sowie Vervielfältigung dieser Unterlage, Verwertung und Mitteilung ihres Inhalts nicht gestattet, soweit nicht ausdrücklich zugestanden. Zuwiderhandlungen verpflichten zu Schadenersatz. Alle Rechte vorbehalten, insbesondere für den Fall der Patenterteilung oder GM-Eintragung. C79000-G8976-C077 Copyright © Siemens AG 1995 to 2001 All Rights Reserved We have checked the contents of this manual for agreement with the hardware described. Since deviations cannot be precluded entirely, we cannot guarantee 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. The reproduction, transmission or use of this document or its contents is not permitted without express written authority. Offenders will be liable for damages. All rights, including rights created by patent grant or registration of a utility or design, are reserved. C79000-G8976-C077 Copyright © Siemens AG 1995 to 2001 All Rights Reserved Nous avons vérifié la conformité du contenu du présent manuel avec le matériel et le logiciel qui y sont décrits. Or, des divergences n'étant pas exclues, nous ne pouvons pas nous porter garants pour la conformité intégrale. Si l'usage du manuel devait révéler des erreurs, nous en tiendrons compte et apporterons les corrections nécessaires dès la prochaine édition. Veuillez nous faire part de vos suggestions. Toute communication ou reproduction de ce support d'informations, toute exploitation ou communication de son contenu sont interdites, sauf autorisation expresse. Tout manquement à cette règle est illicite et expose son auteur au versement de dommages et intérêts. Tous nos droits sont réservés, notamment pour le cas de la délivrance d'un brevet ou celui de l'enregistrement d'un modèle d'utilité. Nous nous réservons le droit de modifier les caractéristiques techniques. C79000-G8976-C077 Copyright © Siemens AG 1995 à 2001 All Rights Reserved Siemens Aktiengesellschaft Elektronikwerk Karlsruhe Printed in the Federal Republic of Germany
SIMATIC NET S7 Programming Interface Description C79000-B8976-C077/07 3
Note We 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 contains the complete and exclusive obligations of Siemens. Any statements contained in this documentation do not create new warranties 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 the 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. General WARNING ! ! This device is electrically operated. In operation, certain parts of this device carry a dangerously high voltage. Failure to heed warnings may result in serious physical injury and/or material damage. Only appropriately qualified personnel may operate this equipment or work in its vicinity. Personnel must be familiar with all warnings and maintenance measures in accordance with these operating instructions. Correct and safe operation of this equipment requires proper transport, storage and assembly as well as careful operator control and maintenance. Personnel qualification requirements Qualified personnel as referred to in the operating instructions or in the warning notes are defined as persons who are 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 technology; − Training in or authorization for the maintenance and use of suitable safety equipment in accordance with current standards in safety technology; − First Aid qualification.
C79000-G8976-C077-07 S7 Programming Interface S7 Programming Interface SIMATIC S7 system components communicate with each other using the S7 communications protocol. To allow programming device/PC application programs access to SIMATIC S7 system components, the SAPI-S7 programming interface was developed. With its C programming interface, you have flexible and simple access to the data of SIMATIC S7 system components. This volume describes the S7 protocol and how to program it. 5
S7 Programming Interface C79000-G8976-C077-07 Notes 6
C79000-G8976-C077-07 S7 Programming Interface 1 The SAPI-S7 Interface........................................................................................................11 1.1 Advantages of S7 Compared With Other Protocols...............................................12 1.2 Advantages of the SAPI-S7 Programming Interface..............................................13 2 Principles of the Programming Interface..........................................................................15 2.1 Synchronous and Asynchronous Job Handling......................................................16 2.2 Advantages of Asynchronous Operation ...............................................................17 2.3 Receive Call and Processing Functions ................................................................18 2.4 Handling S7 Connection Management Services....................................................20 2.5 Error Message Concept ........................................................................................21 2.6 The Trace .............................................................................................................22 2.7 The Mini-DB..........................................................................................................23 2.8 Multi-CP and Multi-User Operation........................................................................24 2.8.1 Assigning VFDs and the S7 Connection List.......................................................25 2.9 Installation and Requirements for Operation .........................................................26 3 The Programming Interface...............................................................................................27 3.1 Overview of the Programming Interface................................................................28 3.1.1 Administrative Services .....................................................................................29 3.1.2 Receive Service.................................................................................................30 3.1.3 S7 Connection Management Services ...............................................................30 3.1.4 Variable Services...............................................................................................32 3.1.5 Block-Oriented Services ....................................................................................35 3.1.6 Message Services..............................................................................................36 3.1.7 VFD Services.....................................................................................................37 3.1.8 Diagnostic Services for Fault-Tolerant Connections ...........................................38 3.2 Administrative Services ........................................................................................39 3.2.1 s7_get_device....................................................................................................43 3.2.2 s7_get_vfd .........................................................................................................45 3.2.3 s7_init ................................................................................................................47 3.2.4 s7_get_cref ........................................................................................................49 3.2.5 s7_get_conn ......................................................................................................50 3.2.6 s7_shut ..............................................................................................................52 3.3 Receive service ....................................................................................................53 3.3.1 s7_receive .........................................................................................................55 3.4 S7 connection management services....................................................................58 3.4.1 s7_initiate_req ...................................................................................................63 3.4.2 s7_get_initiate_cnf .............................................................................................64 3.4.3 s7_await_initiate_req .........................................................................................65 3.4.4 s7_get_await_initiate_cnf ...................................................................................66 3.4.5 s7_get_initiate_ind .............................................................................................67 3.4.6 s7_initiate_rsp....................................................................................................68 3.4.7 s7_abort.............................................................................................................70 3.4.8 s7_get_abort_ind ...............................................................................................71 3.5 Variable Services..................................................................................................72 3.5.1 s7_read_req.......................................................................................................79 7
S7 Programming Interface C79000-G8976-C077-07 3.5.2 s7_get_read_cnf ................................................................................................81 3.5.3 s7_write_req ......................................................................................................83 3.5.4 s7_write_long_req..............................................................................................86 3.5.5 s7_get_write_cnf................................................................................................89 3.5.6 s7_multiple_read_req.........................................................................................90 3.5.7 s7_get_multiple_read_cnf ..................................................................................93 3.5.8 s7_multiple_write_req ........................................................................................96 3.5.9 s7_get_multiple_write_cnf..................................................................................99 3.5.10 s7_cycl_read_init_req ....................................................................................101 3.5.11 s7_get_cycl_read_init_cnf..............................................................................104 3.5.12 s7_cycl_read_start_req ..................................................................................105 3.5.13 s7_get_cycl_read_start_cnf............................................................................106 3.5.14 s7_get_cycl_read_ind ....................................................................................107 3.5.15 s7_get_cycl_read_abort_ind...........................................................................109 3.5.16 s7_cycl_read_stop_req ..................................................................................110 3.5.17 s7_get_cycl_read_stop_cnf ............................................................................111 3.5.18 s7_cycl_read_delete_req ...............................................................................112 3.5.19 s7_get_cycl_read_delete_cnf .........................................................................113 3.5.20 s7_cycl_read..................................................................................................114 3.6 Block-Oriented Services .....................................................................................117 3.6.1 s7_bsend_req ..................................................................................................123 3.6.2 s7_get_bsend_cnf............................................................................................125 3.6.3 s7_brcv_init .....................................................................................................126 3.6.4 s7_get_brcv_ind...............................................................................................128 3.6.5 s7_brcv_stop ...................................................................................................130 3.7 Message Services...............................................................................................131 3.7.1 s7_msg_initiate_req .........................................................................................135 3.7.2 s7_get_msg_initiate_cnf ..................................................................................136 3.7.3 s7_msg_abort_req ...........................................................................................137 3.7.4 s7_get_msg_abort_cnf.....................................................................................138 3.7.5 s7_get_scan_ind ..............................................................................................139 3.7.6 s7_get_alarm_ind ............................................................................................146 3.8 VFD Services......................................................................................................153 3.8.1 s7_vfd_state_req .............................................................................................156 3.8.2 s7_get_vfd_state_cnf.......................................................................................157 3.9 Diagnostic Services for Fault-Tolerant Connections ............................................159 3.9.1 s7_diag_init......................................................................................................161 3.9.2 s7_get_diag_ind...............................................................................................162 3.9.3 s7_diag_stop....................................................................................................164 4 Trace and Mini-DB ...........................................................................................................165 4.1 s7_trace..............................................................................................................166 4.2 s7_write_trace_buffer..........................................................................................167 4.3 s7_mini_db_set...................................................................................................168 4.4 s7_mini_db_get ..................................................................................................174 4.5 s7_last_iec_err_no..............................................................................................176 4.6 s7_last_iec_err_msg ...........................................................................................178 4.7 s7_last_detailed_err_no ......................................................................................179 4.8 s7_last_detailed_err_msg ...................................................................................183 8
分享到:
收藏