etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor etisserant@0: #based on the plcopen standard. etisserant@0: # etisserant@0: #Copyright (C): Edouard TISSERANT and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@0: #modify it under the terms of the GNU Lesser General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Function Block Types definitions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Ordored list of common Function Blocks defined in the IEC 61131-3 etisserant@0: Each block have this attributes: etisserant@0: - "name" : The block name etisserant@0: - "type" : The block type. It can be "function", "functionBlock" or "program" etisserant@0: - "extensible" : Boolean that define if the block is extensible etisserant@0: - "inputs" : List of the block inputs etisserant@0: - "outputs" : List of the block outputs etisserant@0: - "comment" : Comment that will be displayed in the block popup etisserant@0: Inputs and outputs are a tuple of characteristics that are in order: etisserant@0: - The name etisserant@0: - The data type etisserant@0: - The default modifier which can be "none", "negated", "rising" or "falling" etisserant@0: """ etisserant@0: etisserant@0: BlockTypes = [{"name" : "Numerical functions", "list": etisserant@0: [{"name" : "ADD", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], etisserant@0: "outputs" : [("OUT","ANY_NUM","none")], etisserant@0: "comment" : "Addition,\nresult := I1 + I2 + ..."}, etisserant@0: {"name" : "MUL", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], etisserant@0: "outputs" : [("OUT","ANY_NUM","none")], etisserant@0: "comment" : "Multiplication,\nresult := I1 * I2 * ..."}, etisserant@0: {"name" : "SUB", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], etisserant@0: "outputs" : [("OUT","ANY_NUM","none")], etisserant@0: "comment" : "Substration,\nresult := I1 - I2"}, etisserant@0: {"name" : "DIV", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], etisserant@0: "outputs" : [("OUT","ANY_NUM","none")], etisserant@0: "comment" : "Division,\nresult := I1 / I2\n(with integer division, any fractional remainder is truncated)"}, etisserant@0: {"name" : "MOD", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","ANY_INT","none"),("IN2","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_INT","none")], etisserant@0: "comment" : "Modulus,\nresult := I1 MOD I2\n(only valid with integer values)"}, etisserant@0: {"name" : "EXPT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","ANY_REAL","none"),("IN2","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Exponential,\nresult := I1 ^ I2\n(can only take integer exponents)"}, etisserant@0: {"name" : "ABS", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_NUM","none")], etisserant@0: "outputs" : [("OUT","ANY_NUM","none")], etisserant@0: "comment" : "Absolute value (negative values become positive)"}, etisserant@0: {"name" : "SQRT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Square root"}, etisserant@0: {"name" : "LOG", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Logarithm"}, etisserant@0: {"name" : "LN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Natural logarithm"}, etisserant@0: {"name" : "EXP", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Natural exponential"}, etisserant@0: {"name" : "SIN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Sine of input as radians"}, etisserant@0: {"name" : "COS", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Cosine of input as radians"}, etisserant@0: {"name" : "TAN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Tangent of input as radians"}, etisserant@0: {"name" : "ASIN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Principal arc-sine, result in radians"}, etisserant@0: {"name" : "ACOS", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Principal arc-cosine, result in radians"}, etisserant@0: {"name" : "ATAN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_REAL","none")], etisserant@0: "outputs" : [("OUT","ANY_REAL","none")], etisserant@0: "comment" : "Principal arc-tangent, result in radians"} etisserant@0: ]}, etisserant@0: {"name" : "Boolean and bit functions", "list": etisserant@0: [{"name" : "AND", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Result := I1 & I2 & ..."}, etisserant@0: {"name" : "OR", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Result := I1 OR I2 OR ..."}, etisserant@0: {"name" : "XOR", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Result := I1 XOR I2 XOR ..."}, etisserant@0: {"name" : "NOT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","BIT","none")], etisserant@0: "outputs" : [("OUT","BIT","none")], etisserant@0: "comment" : "Result := NOT I1"}, etisserant@0: {"name" : "SHL", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Shift bit-string n bit positions left, zero fill on the right."}, etisserant@0: {"name" : "SHR", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT")], etisserant@0: "comment" : "Shift bit-string right n bit positions, zero fill on the left."}, etisserant@0: {"name" : "ROR", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Shift bit-string right, rotate by n bit positions."}, etisserant@0: {"name" : "ROL", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","ANY_BIT","none")], etisserant@0: "comment" : "Shift bit-string left, rotate by n bit positions."} etisserant@0: ]}, etisserant@0: {"name" : "Selection functions", "list": etisserant@0: [{"name" : "SEL", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("G","BOOL","none"),("IN0","ANY","none"),("IN1","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Selection\nIf G = TRUE then\nResult := IN1 else\nResult := IN2"}, etisserant@0: {"name" : "MAX", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Maximum\nResult := maximum value of all inputs"}, etisserant@0: {"name" : "MIN", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("","ANY","none")], etisserant@0: "comment" : "Minimum\nResult := minimum value of all inputs"}, etisserant@0: {"name" : "LIMIT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("MN","ANY","none"),("IN","ANY","none"),("MX","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Limit\nResult is the value of IN limited between a minimum value of MN and a maximum value of MX."}, etisserant@0: {"name" : "MUX", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("K","ANY_INT","none"),("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Multiplexer\nResult is the value of the input selected by the value of K."} etisserant@0: ]}, etisserant@0: {"name" : "Comparison functions", "list": etisserant@0: [{"name" : "GT", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Greater than\nResult := IN1 > IN2"}, etisserant@0: {"name" : "GE", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Greater than or equal\nResult := IN1 >= IN2"}, etisserant@0: {"name" : "EQ", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Equality\nResult := IN1 = IN2"}, etisserant@0: {"name" : "LE", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Lesser than or equal\nResult := IN1 <= IN2"}, etisserant@0: {"name" : "LT", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Lesser than\nResult := IN1 < IN2"}, etisserant@0: {"name" : "NE", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], etisserant@0: "outputs" : [("OUT","ANY","none")], etisserant@0: "comment" : "Not equal\nResult := IN1 <> IN2"} etisserant@0: ]}, etisserant@0: {"name" : "Character string functions", "list": etisserant@0: [{"name" : "LEFT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","STRING","none"),("L","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Extract left string\nResult is the string formed from L characters from the leftmost character of string IN."}, etisserant@0: {"name" : "RIGHT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","STRING","none"),("L","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Extract right string\nResult is the string formed from L characters from the rightmost part of string IN."}, etisserant@0: {"name" : "MID", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","ANY","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Extract mid string\nResult is a string extracted from the input string IN starting at character position P, and L characters long."}, etisserant@0: {"name" : "CONCAT", "type" : "function", "extensible" : True, etisserant@0: "inputs" : [("IN1","STRING","none"),("IN2","STRING","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Concatenate strings\nResult is a string formed by joining the input strings together. This is an extensible function that can take two or more input strings."}, etisserant@0: {"name" : "INSERT", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","STRING","none"),("IN2","STRING","none"),("P","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Insert string\nThe result is formed by the string IN2 being inserted into string IN1, P character positions from the start of IN1."}, etisserant@0: {"name" : "DELETE", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","STRING","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Delete string\nThe result is formed by a string of characters L in length, being deleted from the input string IN, starting from character position P."}, etisserant@0: {"name" : "REPLACE", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","STRING","none"),("IN2","STRING","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], etisserant@0: "outputs" : [("OUT","STRING","none")], etisserant@0: "comment" : "Replace string\nThe result is formed by replacing L characters in string IN1, starting at position P, with character string in IN2."}, etisserant@0: {"name" : "LEN", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN","STRING","none")], etisserant@0: "outputs" : [("OUT","INT","none")], etisserant@0: "comment" : "Length\nResult is length of the input string."}, etisserant@0: {"name" : "FIND", "type" : "function", "extensible" : False, etisserant@0: "inputs" : [("IN1","STRING","none"),("IN2","STRING","none")], etisserant@0: "outputs" : [("OUT","INT","none")], etisserant@0: "comment" : "Find string\nResult is the position where string IN2 is first found in string IN1.\nIf string IN2 is not found in IN1, the result is 0."}, etisserant@0: ]}, etisserant@0: {"name" : "Standard function blocks", "list": etisserant@0: [{"name" : "SR", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], etisserant@0: "outputs" : [("Q1","BOOL","none")], etisserant@0: "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates."}, etisserant@0: {"name" : "RS", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], etisserant@0: "outputs" : [("Q1","BOOL","none")], etisserant@0: "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates."}, etisserant@0: {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], etisserant@0: "outputs" : [("BUSY","BOOL","none")], etisserant@0: "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."}, etisserant@0: {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CLK","BOOL","none")], etisserant@0: "outputs" : [("Q","BOOL","none")], etisserant@0: "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected."}, etisserant@0: {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CLK","BOOL","none")], etisserant@0: "outputs" : [("Q","BOOL","none")], etisserant@0: "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected."}, etisserant@0: {"name" : "CTU", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("CV","INT","none")], etisserant@0: "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."}, etisserant@0: {"name" : "CTD", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("CV","INT","none")], etisserant@0: "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."}, etisserant@0: {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], etisserant@0: "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")], etisserant@0: "comment" : "Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input ans down on the other."}, etisserant@0: {"name" : "TP", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], etisserant@0: "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."}, etisserant@0: {"name" : "TOF", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], etisserant@0: "comment" : "On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."}, etisserant@0: {"name" : "TON", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], etisserant@0: "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."}, etisserant@0: {"name" : "RTC", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")], etisserant@0: "comment" : "Real time clock\nThe real time clock has many uses including time stamping, setting dates and times of day in batch reports, in alarm messages and so on."}, etisserant@0: {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], etisserant@0: "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")], etisserant@0: "comment" : "Integral\nThe integral function block integrates the value of input XIN over time."}, etisserant@0: {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], etisserant@0: "outputs" : [("XOUT","REAL","none")], etisserant@0: "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."}, etisserant@0: {"name" : "PID", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("AUTO","BOOL","none"),("PV","REAL","none"),("SP","REAL","none"),("X0","REAL","none"),("KP","REAL","none"),("TR","REAL","none"),("TD","REAL","none"),("CYCLE","TIME","none")], etisserant@0: "outputs" : [("XOUT","REAL","none")], etisserant@0: "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."}, etisserant@0: {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none"),("HOLDBACK","BOOL","none"),("ERROR","REAL","none"),("PV","REAL","none")], etisserant@0: "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")], etisserant@0: "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature."}, etisserant@0: {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], etisserant@0: "outputs" : [("Q","BOOL","none")], etisserant@0: "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."}, etisserant@0: {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, etisserant@0: "inputs" : [("PV1","REAL","none"),("PV2","REAL","none"),("RATIO","REAL","none"),("TIMON","TIME","none"),("TIMOFF","TIME","none"),("TOLERANCE","BOOL","none"),("RESET","BOOL","none"),("CYCLE","TIME","none")], etisserant@0: "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")], etisserant@0: "comment" : "Ratio monitor\nThe ratio_monitor function block checks that one process value PV1 is always a given ratio (defined by input RATIO) of a second process value PV2."}, etisserant@0: ]} etisserant@0: ] etisserant@0: etisserant@0: """ etisserant@0: Function that returns the block definition associated to the block type given etisserant@0: """ etisserant@0: etisserant@0: def GetBlockType(type): etisserant@0: for category in BlockTypes: etisserant@0: for blocktype in category["list"]: etisserant@0: if blocktype["name"] == type: etisserant@0: return blocktype etisserant@0: return None etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Data Types definitions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Ordored list of common data types defined in the IEC 61131-3 etisserant@0: Each type is associated to his direct parent type. It defines then a hierarchy etisserant@0: between type that permits to make a comparison of two types etisserant@0: """ etisserant@0: etisserant@0: TypeHierarchy = {"ANY" : None, etisserant@0: "ANY_DERIVED" : "ANY", etisserant@0: "ANY_ELEMENTARY" : "ANY", etisserant@0: "ANY_MAGNITUDE": "ANY_ELEMENTARY", etisserant@0: "ANY_BIT" : "ANY_ELEMENTARY", etisserant@0: "ANY_STRING" : "ANY_ELEMENTARY", etisserant@0: "ANY_DATE" : "ANY_ELEMENTARY", etisserant@0: "ANY_NUM" : "ANY_MAGNITUDE", etisserant@0: "ANY_REAL" : "ANY_NUM", etisserant@0: "ANY_INT" : "ANY_NUM", etisserant@0: "REAL" : "ANY_REAL", etisserant@0: "LREAL" : "ANY_REAL", etisserant@0: "SINT" : "ANY_INT", etisserant@0: "INT" : "ANY_INT", etisserant@0: "DINT" : "ANY_INT", etisserant@0: "LINT" : "ANY_INT", etisserant@0: "USINT" : "ANY_INT", etisserant@0: "UINT" : "ANY_INT", etisserant@0: "UDINT" : "ANY_INT", etisserant@0: "ULINT" : "ANY_INT", etisserant@0: "TIME" : "ANY_MAGNITUDE", etisserant@0: "BOOL" : "ANY_BIT", etisserant@0: "BYTE" : "ANY_BIT", etisserant@0: "WORD" : "ANY_BIT", etisserant@0: "DWORD" : "ANY_BIT", etisserant@0: "LWORD" : "ANY_BIT", etisserant@0: "STRING" : "ANY_STRING", etisserant@0: "WSTRING" : "ANY_STRING", etisserant@0: "DATE" : "ANY_DATE", etisserant@0: "TOD" : "ANY_DATE", etisserant@0: "DT" : "ANY_DATE" etisserant@0: } etisserant@0: etisserant@0: """ etisserant@0: Function that returns if the given data type is the same that "reference" or one etisserant@0: of its children types etisserant@0: """ etisserant@0: etisserant@0: def IsOfType(test, reference): etisserant@0: while test != None: etisserant@0: if test == reference: etisserant@0: return True etisserant@0: test = TypeHierarchy[test] etisserant@0: return False etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Languages Keywords etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: etisserant@0: # Keywords for Pou Declaration etisserant@0: POU_KEYWORDS = ["FUNCTION", "END_FUNCTION", "FUNCTION_BLOCK", "END_FUNCTION_BLOCK", etisserant@0: "PROGRAM", "END_PROGRAM", "EN", "ENO", "F_EDGE", "R_EDGE"] etisserant@0: for category in BlockTypes: etisserant@0: for block in category["list"]: etisserant@0: if block["name"] not in POU_KEYWORDS: etisserant@0: POU_KEYWORDS.append(block["name"]) etisserant@0: etisserant@0: etisserant@0: # Keywords for Type Declaration etisserant@0: TYPE_KEYWORDS = ["TYPE", "END_TYPE", "STRUCT", "END_STRUCT", "ARRAY", "OF", "T", etisserant@0: "D", "TIME_OF_DAY", "DATE_AND_TIME"] etisserant@0: TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS]) etisserant@0: etisserant@0: etisserant@0: # Keywords for Variable Declaration etisserant@0: VAR_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", etisserant@0: "VAR_EXTERNAL", "END_VAR", "AT", "CONSTANT", "RETAIN", "NON_RETAIN"] etisserant@0: etisserant@0: etisserant@0: # Keywords for Configuration Declaration etisserant@0: CONFIG_KEYWORDS = ["CONFIGURATION", "END_CONFIGURATION", "RESOURCE", "ON", "END_RESOURCE", etisserant@0: "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK", "VAR_ACCESS", "VAR_CONFIG", etisserant@0: "VAR_GLOBAL", "END_VAR"] etisserant@0: etisserant@0: etisserant@0: # Keywords for Structured Function Chart etisserant@0: SFC_KEYWORDS = ["ACTION", "END_ACTION", "INITIAL_STEP", "STEP", "END_STEP", "TRANSITION", etisserant@0: "FROM", "TO", "END_TRANSITION"] etisserant@0: etisserant@0: etisserant@0: # Keywords for Instruction List etisserant@0: IL_KEYWORDS = ["LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN", etisserant@0: "XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE", etisserant@0: "LE", "LT", "JMP", "JMPC", "JMPNC", "CAL", "CALC", "CALNC", "RET", "RETC", "RETNC"] etisserant@0: etisserant@0: etisserant@0: # Keywords for Instruction List and Structured Text etisserant@0: ST_KEYWORDS = ["IF", "THEN", "ELSIF", "ELSE", "END_IF", "CASE", "OF", "END_CASE", etisserant@0: "FOR", "TO", "BY", "DO", "END_FOR", "WHILE", "DO", "END_WHILE", "REPEAT", "UNTIL", etisserant@0: "END_REPEAT", "EXIT", "RETURN", "NOT", "MOD", "AND", "XOR", "OR"] etisserant@0: etisserant@0: etisserant@0: # All the keywords of IEC etisserant@0: IEC_KEYWORDS = ["E", "TRUE", "FALSE"] etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in POU_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in TYPE_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in VAR_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in CONFIG_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in SFC_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in IL_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: IEC_KEYWORDS.extend([keyword for keyword in ST_KEYWORDS if keyword not in IEC_KEYWORDS]) etisserant@0: