1、NEMA Standards PublicationNational Electrical Manufacturers AssociationNEMA IA 2.8-2005Programmable Controllers Part 8: Guidelines for the Application and Implementation of Programming LanguagesNEMA Standards Publication IA 2.8-2005 (Adoption of IEC Publication TR 61131-8) Programmable Controllers P
2、art 8: Guidelines for the Application and Implementation of Programming Languages Published by: National Electrical Manufacturers Association 1300 North 17th Street, Suite 1752 Rosslyn, Virginia 22209 www.nema.org Copyright 2005 by the National Electrical Manufacturers Association. All rights includ
3、ing translation into other languages, reserved under the Universal Copyright Convention, the Berne Convention for the Protection of Literary and Artistic Works, and the International and Pan American Copyright Conventions. NOTICE AND DISCLAIMER The information in this publication was considered tech
4、nically sound by the consensus of persons engaged in the development and approval of the document at the time it was developed. Consensus does not necessarily mean that there is unanimous agreement among every person participating in the development of this document. The National Electrical Manufact
5、urers Association (NEMA) standards and guideline publications, of which the document contained herein is one, are developed through a voluntary consensus standards development process. This process brings together volunteers and/or seeks out the views of persons who have an interest in the topic cov
6、ered by this publication. While NEMA administers the process and establishes rules to promote fairness in the development of consensus, it does not write the document and it does not independently test, evaluate, or verify the accuracy or completeness of any information or the soundness of any judgm
7、ents contained in its standards and guideline publications. NEMA disclaims liability for any personal injury, property, or other damages of any nature whatsoever, whether special, indirect, consequential, or compensatory, directly or indirectly resulting from the publication, use of, application, or
8、 reliance on this document. NEMA disclaims and makes no guaranty or warranty, express or implied, as to the accuracy or completeness of any information published herein, and disclaims and makes no warranty that the information in this document will fulfill any of your particular purposes or needs. N
9、EMA does not undertake to guarantee the performance of any individual manufacturer or sellers products or services by virtue of this standard or guide. In publishing and making this document available, NEMA is not undertaking to render professional or other services for or on behalf of any person or
10、 entity, nor is NEMA undertaking to perform any duty owed by any person or entity to someone else. Anyone using this document should rely on his or her own independent judgment or, as appropriate, seek the advice of a competent professional in determining the exercise of reasonable care in any given
11、 circumstances. Information and other standards on the topic covered by this publication may be available from other sources, which the user may wish to consult for additional views or information not covered by this publication. NEMA has no power, nor does it undertake to police or enforce complian
12、ce with the contents of this document. NEMA does not certify, test, or inspect products, designs, or installations for safety or health purposes. Any certification or other statement of compliance with any health or safetyrelated information in this document shall not be attributable to NEMA and is
13、solely the responsibility of the certifier or maker of the statement. NEMA IA 2.8-2005 Page i Copyright 2005 by the National Electrical Manufacturers Association. CONTENTS Page Foreword . ii Referenced Standards .iii Amendmentsiv IEC TR 61131-8. 1 NEMA IA 2.8-2005 Page ii Copyright 2005 by the Natio
14、nal Electrical Manufacturers Association. Foreword This Standards Publication is a NEMA Authorized Engineering Information adopted from IEC TR 61131-8, Programmable ControllersPart 8: Guidelines for the Application and Implementation of Programming Languages. IEC TR 61131-8 has been published by the
15、 International Electrotechnical Commission as a Type 3 Technical Report. This NEMA Standards Publication was supported and reviewed by the Programmable Controller Technical Committee of the NEMA Automation Products and Systems Section. It was approved in accordance with the bylaws of NEMA and supers
16、edes applicable portions of NEMA Standards Publication ICS 3-1988, Part 3-304. This Standards Publication represents many years of direct NEMA member participation in IEC Subcommittee 65B/Working Group 7, and reflects the input provided to the IEC from the Programmable Controller Technical Committee
17、. NEMA Standards Publications are subject to periodic review. They are revised frequently to reflect user input and to meet changing conditions and technical progress. Users should secure the latest editions. Proposed revisions to this Standards Publication should be submitted to: Vice President, Te
18、chnical Services National Electrical Manufacturers Association 1300 North 17th Street, Suite 1752 Rosslyn, Virginia 22209 NEMA IA 2.8-2005 Page iii Copyright 2005 by the National Electrical Manufacturers Association. Referenced Standards This NEMA Standards Publication references standards published
19、 by the International Electrotechnical Commission (IEC), the International Organization for Standardization (ISO), and the National Fire Protection Association (NFPA). Copies of these standards are available from: American National Standards Institute 11 West 42nd Street New York, NY 10036 NEMA IA 2
20、.8-2005 Page iv Copyright 2005 by the National Electrical Manufacturers Association. Amendments IEC TR 61131-8, Programmable ControllersPart 8: Guidelines for the Application and Implementation of Programming Languages, is adopted in its entirety. Authorized Engineering Information When the phrase “
21、national code” or the like is used in IEC TR 61131-8, reference to ANSI/NFPA 70, National Electrical Code, and other applicable codes is to be understood. Authorized Engineering Information Where a conflict exists between the provisions of IA 2.8 and other NEMA Standards Publications, the provisions
22、 of IA 2.8 should take precedence in the area of programmable controllers and their associated peripherals. Authorized Engineering Information TECHNICALREPORTIECTR 61131-8Second edition2003-09Programmable controllers Part 8:Guidelines for the application and implementationof programming languagesAut
23、omates programmables Partie 8:Lignes directrices pour lapplication et la mise en oeuvredes langages de programmationReference numberIEC/TR 61131-8:2003(E)Publication numbering As from 1 January 1997 all IEC publications are issued with a designation in the 60000 series. For example, IEC 34-1 is now
24、referred to as IEC 60034-1. Consolidated editions The IEC is now publishing consolidated versions of its publications. For example, edition numbers 1.0, 1.1 and 1.2 refer, respectively, to the base publication, the base publication incorporating amendment 1 and the base publication incorporating ame
25、ndments 1 and 2. Further information on IEC publications The technical content of IEC publications is kept under constant review by the IEC, thus ensuring that the content reflects current technology. Information relating to this publication, including its validity, is available in the IEC Catalogue
26、 of publications (see below) in addition to new editions, amendments and corrigenda. Information on the subjects under consideration and work in progress undertaken by the technical committee which has prepared this publication, as well as the list of publications issued, is also available from the
27、following: IEC Web Site (www.iec.ch) Catalogue of IEC publications The on-line catalogue on the IEC web site (www.iec.ch/searchpub) enables you to search by a variety of criteria including text searches, technical committees and date of publication. On-line information is also available on recently
28、issued publications, withdrawn and replaced publications, as well as corrigenda. IEC Just Published This summary of recently issued publications (www.iec.ch/online_news/ justpub) is also available by email. Please contact the Customer Service Centre (see below) for further information. Customer Serv
29、ice Centre If you have any questions regarding this publication or need further assistance, please contact the Customer Service Centre: Email: custserviec.ch Tel: +41 22 919 02 11 Fax: +41 22 919 03 00 TECHNICALREPORTIECTR 61131-8Second edition2003-09Programmable controllers Part 8:Guidelines for th
30、e application and implementationof programming languagesAutomates programmables Partie 8:Lignes directrices pour lapplication et la mise en oeuvredes langages de programmationPRICE CODE IEC 2003 Copyright - all rights reservedNo part of this publication may be reproduced or utilized in any form or b
31、y any means, electronic ormechanical, including photocopying and microfilm, without permission in writing from the publisher.International Electrotechnical Commission, 3, rue de Varemb, PO Box 131, CH-1211 Geneva 20, SwitzerlandTelephone: +41 22 919 02 11 Telefax: +41 22 919 03 00 E-mail: inmailiec.
32、ch Web: www.iec.chXDFor price, see current catalogueCommission Electrotechnique InternationaleInternational Electrotechnical Commission 2 TR 61131-8 IEC:2003(E)CONTENTSFOREWORD 6INTRODUCTION 81 General 91.1 Scope . 91.2 Normative references 91.3 Abbreviated terms. 91.4 Overview .102 Introduction to
33、IEC 61131-3.102.1 General considerations 102.2 Overcoming historical limitations 122.3 Basic features in IEC 61131-3132.4 New features in the second edition of IEC 61131-3.142.5 Software engineering considerations 142.5.1 Application of software engineering principles.142.5.2 Portability.173 Applica
34、tion guidelines .183.1 Use of data types.183.1.1 Type versus variable initialization .183.1.2 Use of enumerated and subrange types183.1.3 Use of BCD data 193.1.4 Use of REAL data types .213.1.5 Use of character string data types 213.1.6 Use of time data types233.1.7 Declaration and use of multi-elem
35、ent variables.233.1.8 Use of bit-string functions.243.1.9 Strongly typed assignment253.2 Data passing263.2.1 Global and external variables .273.2.2 In-out (VAR_IN_OUT) variables273.2.3 Formal and non-formal invocations and argument lists303.3 Use of function blocks323.3.1 Function block types and in
36、stances 323.3.2 Scope of data within function blocks .333.3.3 Function block access and invocation.343.4 Differences between function block instances and functions .353.5 Use of indirectly referenced function block instances353.5.1 Establishing an indirect function block instance reference.353.5.2 A
37、ccess to indirectly referenced function block instances .373.5.3 Invocation of indirectly referenced function block instances 383.5.4 Recursion of indirectly referenced function block instances.403.5.5 Execution control of indirectly referenced function block instances403.5.6 Use of indirectly refer
38、enced function block instances in functions403.6 Recursion within programmable controller programming languages 413.7 Single and multiple invocation 41TR 61131-8 IEC:2003(E) 3 3.8 Language specific features 423.8.1 Edge-triggered functionality423.8.2 Use of EN/ENO in functions and function blocks.43
39、3.8.3 Use of non-IEC 61131-3 languages 443.9 Use of SFC elements .453.9.1 Action control.453.9.2 Boolean actions .463.9.3 Non-SFC actions493.9.4 SFC actions .513.9.5 SFC function blocks .513.9.6 “Indicator” variables .523.10 Scheduling, concurrency, and synchronization mechanisms523.10.1 Operating s
40、ystem issues 523.10.2 Task scheduling.543.10.3 Semaphores.553.10.4 Messaging .563.10.5 Time stamping .563.11 Communication facilities in ISO/IEC 9506/5 and IEC 61131-5.573.11.1 Communication channels .573.11.2 Reading and writing variables.573.11.3 Communication function blocks 583.12 Deprecated pro
41、gramming practices593.12.1 Global variables .593.12.2 Jumps in FBD language .593.12.3 Multiple invocations of function block instances in FBD.593.12.4 Coupling of SFC networks 593.12.5 Dynamic modification of task priorities603.12.6 Execution control of function block instances by tasks 603.12.7 Inc
42、orrect use of WHILE and REPEAT constructs 603.13 Use of TRUNC and REAL_TO_INT functions614 Implementation guidelines.624.1 Resource allocation .624.2 Implementation of data types .624.2.1 REAL and LREAL data types 624.2.2 Bit strings.624.2.3 Character strings634.2.4 Time data types .634.2.5 Multi-el
43、ement variables 634.3 Execution of functions and function blocks .644.3.1 Functions.644.3.2 Function blocks644.4 Implementation of SFCs.654.4.1 General considerations 654.4.2 SFC evolution 664.5 Task scheduling.664.5.1 Classification of tasks 664.5.2 Task priorities 67 4 TR 61131-8 IEC:2003(E)4.6 Er
44、ror handling 674.6.1 Error-handling mechanisms674.6.2 Run-time error-handling procedures .694.7 System interface 714.8 Compliance714.8.1 Compliance statement714.8.2 Controller instruction sets.714.8.3 Compliance testing.725 PSE requirements .725.1 User interface 725.2 Programming of programs, functi
45、ons and function blocks .735.3 Application design and configuration 735.4 Separate compilation .745.5 Separation of interface and body755.5.1 Invocation of a function from a programming unit755.5.2 Declaration and invocation of a function block instance.765.6 Linking of configuration elements with p
46、rograms.775.7 Library management 795.8 Analysis tools.795.8.1 Simulation and debugging 795.8.2 Performance estimation .805.8.3 Feedback loop analysis 805.8.4 SFC analysis805.9 Documentation requirements835.10 Security of data and programs835.11 On-line facilities .83Annex A (informative) Changes to
47、IEC 61131-3, Second edition84Annex B (informative) Software quality measures94Annex C (informative) Relationships to other standards 96INDEX.97Bibliography 109Figure 1 A distributed application11Figure 2 Stand-alone applications .11Figure 3 Cyclic or periodic scanning of a program .12Figure 4 Functi
48、on block BCD_DIFF.20Figure 5 Function block SBCD_DIFFF.21Figure 6 ST example of time data type usage23Figure 7 Example of declaration and use of “anonymous array types”24Figure 8 Examples of VAR_IN_OUT usage .29Figure 9 Hiding of function block instances .34Figure 10 Graphical use of a function bloc
49、k name .37Figure 11 Access to an indirectly referenced function block instance.37TR 61131-8 IEC:2003(E) 5 Figure 12 Invocation of an indirectly referenced function block instance 39Figure 13 Timing of edge triggered functionality 43Figure 14 Execution control example 44Figure 15 Timing of Boolean actions .49Figure 16 Example of a programmed non-Boolean action50Figure 17 Use of the pulse (P) qualifier .51Figure 18 An SFC function block.52Figure 19 Example of i