andrej@1511: #!/usr/bin/env python andrej@1511: # -*- coding: utf-8 -*- andrej@1511: andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1511: # andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD andrej@1511: # andrej@1511: # See COPYING file for copyrights details. andrej@1511: # andrej@1511: # This program is free software; you can redistribute it and/or andrej@1511: # modify it under the terms of the GNU General Public License andrej@1511: # as published by the Free Software Foundation; either version 2 andrej@1511: # of the License, or (at your option) any later version. andrej@1511: # andrej@1511: # This program is distributed in the hope that it will be useful, andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1511: # GNU General Public License for more details. andrej@1511: # andrej@1511: # You should have received a copy of the GNU General Public License andrej@1511: # along with this program; if not, write to the Free Software andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1511: andrej@1511: Edouard@1390: from os.path import join, split, realpath Edouard@1390: sd = split(realpath(__file__))[0] Edouard@1390: Edouard@1390: # Override gettext _ in this module Edouard@1390: # since we just want string to be added to dictionnary Edouard@1390: # but translation should happen here Edouard@1390: _ = lambda x:x Edouard@1390: Edouard@1390: LANGUAGES = ["IL","ST","FBD","LD","SFC"] Edouard@1390: Edouard@1390: LOCATIONDATATYPES = {"X" : ["BOOL"], Edouard@1390: "B" : ["SINT", "USINT", "BYTE", "STRING"], Edouard@1390: "W" : ["INT", "UINT", "WORD", "WSTRING"], Edouard@1390: "D" : ["DINT", "UDINT", "REAL", "DWORD"], Edouard@1411: "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} Edouard@1390: Edouard@1390: #------------------------------------------------------------------------------- Edouard@1390: # Function Block Types definitions Edouard@1390: #------------------------------------------------------------------------------- Edouard@1390: Edouard@1390: StdTC6Libs = [(_("Standard function blocks"), join(sd, "Standard_Function_Blocks.xml")), Edouard@1390: (_("Additional function blocks"),join(sd, "Additional_Function_Blocks.xml"))] Edouard@1390: Edouard@1390: StdFuncsCSV = join(sd,"iec_std.csv") Edouard@1390: Edouard@1390: # FIXME : since std fb now loaded from TC6 file, is that still necessary ? Edouard@1390: StdBlockComments = { Edouard@1390: "SR": _("SR bistable\nThe SR bistable is a latch where the Set dominates."), Edouard@1390: "RS": _("RS bistable\nThe RS bistable is a latch where the Reset dominates."), Edouard@1390: "SEMA": _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."), Edouard@1390: "R_TRIG": _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."), Edouard@1390: "F_TRIG": _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."), Edouard@1390: "CTU": _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."), Edouard@1390: "CTD": _("Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."), Edouard@1390: "CTUD": _("Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input and down on the other."), Edouard@1390: "TP": _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."), Edouard@1390: "TON": _("On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."), Edouard@1390: "TOF": _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."), Edouard@1390: "RTC": _("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."), Edouard@1390: "INTEGRAL": _("Integral\nThe integral function block integrates the value of input XIN over time."), Edouard@1390: "DERIVATIVE": _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."), Edouard@1390: "PID": _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."), Edouard@1390: "RAMP": _("Ramp\nThe RAMP function block is modelled on example given in the standard."), Edouard@1390: "HYSTERESIS": _("Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."), Edouard@1390: } Edouard@1390: Edouard@1390: for block_type in ["CTU", "CTD", "CTUD"]: Edouard@1390: for return_type in ["DINT", "LINT", "UDINT", "ULINT"]: Edouard@1390: StdBlockComments["%s_%s" % (block_type, return_type)] = StdBlockComments[block_type] Edouard@1390: Edouard@1390: def GetBlockInfos(pou): Edouard@1390: infos = pou.getblockInfos() Edouard@1390: # FIXME : as well Edouard@1390: infos["comment"] = StdBlockComments[infos["name"]] Edouard@1390: infos["inputs"] = [ Edouard@1390: (var_name, var_type, "rising") Edouard@1390: if var_name in ["CU", "CD"] Edouard@1390: else (var_name, var_type, var_modifier) Edouard@1390: for var_name, var_type, var_modifier in infos["inputs"]] Edouard@1390: return infos Edouard@1390: Edouard@1390: #------------------------------------------------------------------------------- Edouard@1390: # Data Types definitions Edouard@1390: #------------------------------------------------------------------------------- Edouard@1390: Edouard@1390: """ Edouard@1390: Ordored list of common data types defined in the IEC 61131-3 Edouard@1390: Each type is associated to his direct parent type. It defines then a hierarchy Edouard@1390: between type that permits to make a comparison of two types Edouard@1390: """ Edouard@1390: TypeHierarchy_list = [ Edouard@1390: ("ANY", None), Edouard@1390: ("ANY_DERIVED", "ANY"), Edouard@1390: ("ANY_ELEMENTARY", "ANY"), Edouard@1390: ("ANY_MAGNITUDE", "ANY_ELEMENTARY"), Edouard@1390: ("ANY_BIT", "ANY_ELEMENTARY"), Edouard@1390: ("ANY_NBIT", "ANY_BIT"), Edouard@1390: ("ANY_STRING", "ANY_ELEMENTARY"), Edouard@1390: ("ANY_DATE", "ANY_ELEMENTARY"), Edouard@1390: ("ANY_NUM", "ANY_MAGNITUDE"), Edouard@1390: ("ANY_REAL", "ANY_NUM"), Edouard@1390: ("ANY_INT", "ANY_NUM"), Edouard@1390: ("ANY_SINT", "ANY_INT"), Edouard@1390: ("ANY_UINT", "ANY_INT"), Edouard@1390: ("BOOL", "ANY_BIT"), Edouard@1390: ("SINT", "ANY_SINT"), Edouard@1390: ("INT", "ANY_SINT"), Edouard@1390: ("DINT", "ANY_SINT"), Edouard@1390: ("LINT", "ANY_SINT"), Edouard@1390: ("USINT", "ANY_UINT"), Edouard@1390: ("UINT", "ANY_UINT"), Edouard@1390: ("UDINT", "ANY_UINT"), Edouard@1390: ("ULINT", "ANY_UINT"), Edouard@1390: ("REAL", "ANY_REAL"), Edouard@1390: ("LREAL", "ANY_REAL"), Edouard@1390: ("TIME", "ANY_MAGNITUDE"), Edouard@1390: ("DATE", "ANY_DATE"), Edouard@1390: ("TOD", "ANY_DATE"), Edouard@1390: ("DT", "ANY_DATE"), Edouard@1390: ("STRING", "ANY_STRING"), Edouard@1390: ("BYTE", "ANY_NBIT"), Edouard@1390: ("WORD", "ANY_NBIT"), Edouard@1390: ("DWORD", "ANY_NBIT"), Edouard@1390: ("LWORD", "ANY_NBIT") Edouard@1390: #("WSTRING", "ANY_STRING") # TODO Edouard@1390: ] Edouard@1390: Edouard@1412: DefaultType = "DINT" Edouard@1412: Edouard@1390: DataTypeRange_list = [ Edouard@1390: ("SINT", (-2**7, 2**7 - 1)), Edouard@1390: ("INT", (-2**15, 2**15 - 1)), Edouard@1390: ("DINT", (-2**31, 2**31 - 1)), Edouard@1390: ("LINT", (-2**31, 2**31 - 1)), Edouard@1390: ("USINT", (0, 2**8 - 1)), Edouard@1390: ("UINT", (0, 2**16 - 1)), Edouard@1390: ("UDINT", (0, 2**31 - 1)), Edouard@1390: ("ULINT", (0, 2**31 - 1)) Edouard@1390: ] Edouard@1390: Edouard@1390: ANY_TO_ANY_FILTERS = { Edouard@1390: "ANY_TO_ANY":[ Edouard@1390: # simple type conv are let as C cast Edouard@1390: (("ANY_INT","ANY_BIT"),("ANY_NUM","ANY_BIT")), Edouard@1390: (("ANY_REAL",),("ANY_REAL",)), Edouard@1390: # REAL_TO_INT Edouard@1390: (("ANY_REAL",),("ANY_SINT",)), Edouard@1390: (("ANY_REAL",),("ANY_UINT",)), Edouard@1390: (("ANY_REAL",),("ANY_BIT",)), Edouard@1390: # TO_TIME Edouard@1390: (("ANY_INT","ANY_BIT"),("ANY_DATE","TIME")), Edouard@1390: (("ANY_REAL",),("ANY_DATE","TIME")), Edouard@1390: (("ANY_STRING",), ("ANY_DATE","TIME")), Edouard@1390: # FROM_TIME Edouard@1390: (("ANY_DATE","TIME"), ("ANY_REAL",)), Edouard@1390: (("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT")), Edouard@1390: (("TIME",), ("ANY_STRING",)), Edouard@1390: (("DATE",), ("ANY_STRING",)), Edouard@1390: (("TOD",), ("ANY_STRING",)), Edouard@1390: (("DT",), ("ANY_STRING",)), Edouard@1390: # TO_STRING Edouard@1390: (("BOOL",), ("ANY_STRING",)), Edouard@1390: (("ANY_BIT",), ("ANY_STRING",)), Edouard@1390: (("ANY_REAL",), ("ANY_STRING",)), Edouard@1390: (("ANY_SINT",), ("ANY_STRING",)), Edouard@1390: (("ANY_UINT",), ("ANY_STRING",)), Edouard@1390: # FROM_STRING Edouard@1390: (("ANY_STRING",), ("BOOL",)), Edouard@1390: (("ANY_STRING",), ("ANY_BIT",)), Edouard@1390: (("ANY_STRING",), ("ANY_SINT",)), Edouard@1390: (("ANY_STRING",), ("ANY_UINT",)), Edouard@1390: (("ANY_STRING",), ("ANY_REAL",))], Edouard@1390: "BCD_TO_ANY":[ Edouard@1390: (("BYTE",),("USINT",)), Edouard@1390: (("WORD",),("UINT",)), Edouard@1390: (("DWORD",),("UDINT",)), Edouard@1390: (("LWORD",),("ULINT",))], Edouard@1390: "ANY_TO_BCD":[ Edouard@1390: (("USINT",),("BYTE",)), Edouard@1390: (("UINT",),("WORD",)), Edouard@1390: (("UDINT",),("DWORD",)), Edouard@1390: (("ULINT",),("LWORD",))] Edouard@1390: } Edouard@1390: Edouard@1390: # remove gettext override Edouard@1390: del _