plcopen/structures.py
changeset 93 c3c24b979a4d
parent 92 76d5001393df
child 98 ec5d7af033d8
equal deleted inserted replaced
92:76d5001393df 93:c3c24b979a4d
    60             blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
    60             blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
    61             if not connectionPoint or block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
    61             if not connectionPoint or block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY():
    62                 return generator.ExtractModifier(variable, "%s.%s"%(name, variable.getFormalParameter()))
    62                 return generator.ExtractModifier(variable, "%s.%s"%(name, variable.getFormalParameter()))
    63         raise ValueError, "No output variable found"
    63         raise ValueError, "No output variable found"
    64 
    64 
       
    65 def initialise_block(type, name):
       
    66     return [(type, name, None, None)]
       
    67 
    65 #-------------------------------------------------------------------------------
    68 #-------------------------------------------------------------------------------
    66 #                        Function Block Types definitions
    69 #                        Function Block Types definitions
    67 #-------------------------------------------------------------------------------
    70 #-------------------------------------------------------------------------------
    68 
    71 
    69 
    72 
    86 BlockTypes = [{"name" : "Standard function blocks", "list":
    89 BlockTypes = [{"name" : "Standard function blocks", "list":
    87                [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
    90                [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
    88                     "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
    91                     "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
    89                     "outputs" : [("Q1","BOOL","none")],
    92                     "outputs" : [("Q1","BOOL","none")],
    90                     "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates.",
    93                     "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates.",
    91                     "generate" : generate_block},
    94                     "generate" : generate_block, "initialise" : initialise_block},
    92                 {"name" : "RS", "type" : "functionBlock", "extensible" : False, 
    95                 {"name" : "RS", "type" : "functionBlock", "extensible" : False, 
    93                     "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], 
    96                     "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], 
    94                     "outputs" : [("Q1","BOOL","none")],
    97                     "outputs" : [("Q1","BOOL","none")],
    95                     "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates.",
    98                     "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates.",
    96                     "generate" : generate_block},
    99                     "generate" : generate_block, "initialise" : initialise_block},
    97                 {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, 
   100                 {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, 
    98                     "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], 
   101                     "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], 
    99                     "outputs" : [("BUSY","BOOL","none")],
   102                     "outputs" : [("BUSY","BOOL","none")],
   100                     "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources.",
   103                     "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources.",
   101                     "generate" : generate_block},
   104                     "generate" : generate_block, "initialise" : initialise_block},
   102                 {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, 
   105                 {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, 
   103                     "inputs" : [("CLK","BOOL","none")], 
   106                     "inputs" : [("CLK","BOOL","none")], 
   104                     "outputs" : [("Q","BOOL","none")],
   107                     "outputs" : [("Q","BOOL","none")],
   105                     "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected.",
   108                     "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected.",
   106                     "generate" : generate_block},
   109                     "generate" : generate_block, "initialise" : initialise_block},
   107                 {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, 
   110                 {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, 
   108                     "inputs" : [("CLK","BOOL","none")], 
   111                     "inputs" : [("CLK","BOOL","none")], 
   109                     "outputs" : [("Q","BOOL","none")],
   112                     "outputs" : [("Q","BOOL","none")],
   110                     "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected.",
   113                     "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected.",
   111                     "generate" : generate_block},
   114                     "generate" : generate_block, "initialise" : initialise_block},
   112                 {"name" : "CTU", "type" : "functionBlock", "extensible" : False, 
   115                 {"name" : "CTU", "type" : "functionBlock", "extensible" : False, 
   113                     "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], 
   116                     "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], 
   114                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
   117                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
   115                     "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value.",
   118                     "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value.",
   116                     "generate" : generate_block},
   119                     "generate" : generate_block, "initialise" : initialise_block},
   117                 {"name" : "CTD", "type" : "functionBlock", "extensible" : False, 
   120                 {"name" : "CTD", "type" : "functionBlock", "extensible" : False, 
   118                     "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], 
   121                     "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], 
   119                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
   122                     "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
   120                     "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value.",
   123                     "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value.",
   121                     "generate" : generate_block},
   124                     "generate" : generate_block, "initialise" : initialise_block},
   122                 {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, 
   125                 {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, 
   123                     "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], 
   126                     "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], 
   124                     "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")],
   127                     "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")],
   125                     "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.",
   128                     "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.",
   126                     "generate" : generate_block},
   129                     "generate" : generate_block, "initialise" : initialise_block},
   127                 {"name" : "TP", "type" : "functionBlock", "extensible" : False, 
   130                 {"name" : "TP", "type" : "functionBlock", "extensible" : False, 
   128                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   131                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   129                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   132                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   130                     "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration.",
   133                     "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration.",
   131                     "generate" : generate_block},
   134                     "generate" : generate_block, "initialise" : initialise_block},
   132                 {"name" : "TOF", "type" : "functionBlock", "extensible" : False, 
   135                 {"name" : "TOF", "type" : "functionBlock", "extensible" : False, 
   133                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   136                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   134                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   137                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   135                     "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.",
   138                     "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.",
   136                     "generate" : generate_block},
   139                     "generate" : generate_block, "initialise" : initialise_block},
   137                 {"name" : "TON", "type" : "functionBlock", "extensible" : False, 
   140                 {"name" : "TON", "type" : "functionBlock", "extensible" : False, 
   138                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   141                     "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
   139                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   142                     "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
   140                     "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false.",
   143                     "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false.",
   141                     "generate" : generate_block},
   144                     "generate" : generate_block, "initialise" : initialise_block},
   142                 {"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
   145                 {"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
   143                     "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
   146                     "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
   144                     "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],
   147                     "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],
   145                     "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.",
   148                     "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.",
   146                     "generate" : generate_block},
   149                     "generate" : generate_block, "initialise" : initialise_block},
   147                 {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, 
   150                 {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, 
   148                     "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], 
   151                     "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], 
   149                     "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")],
   152                     "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")],
   150                     "comment" : "Integral\nThe integral function block integrates the value of input XIN over time.",
   153                     "comment" : "Integral\nThe integral function block integrates the value of input XIN over time.",
   151                     "generate" : generate_block},
   154                     "generate" : generate_block, "initialise" : initialise_block},
   152                 {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, 
   155                 {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, 
   153                     "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], 
   156                     "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], 
   154                     "outputs" : [("XOUT","REAL","none")],
   157                     "outputs" : [("XOUT","REAL","none")],
   155                     "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN.",
   158                     "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN.",
   156                     "generate" : generate_block},
   159                     "generate" : generate_block, "initialise" : initialise_block},
   157                 {"name" : "PID", "type" : "functionBlock", "extensible" : False, 
   160                 {"name" : "PID", "type" : "functionBlock", "extensible" : False, 
   158                     "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")], 
   161                     "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")], 
   159                     "outputs" : [("XOUT","REAL","none")],
   162                     "outputs" : [("XOUT","REAL","none")],
   160                     "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control.",
   163                     "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control.",
   161                     "generate" : generate_block},
   164                     "generate" : generate_block, "initialise" : initialise_block},
   162                 {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, 
   165                 {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, 
   163                     "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")], 
   166                     "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")], 
   164                     "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")],
   167                     "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")],
   165                     "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature.",
   168                     "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature.",
   166                     "generate" : generate_block},
   169                     "generate" : generate_block, "initialise" : initialise_block},
   167                 {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, 
   170                 {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, 
   168                     "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], 
   171                     "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], 
   169                     "outputs" : [("Q","BOOL","none")],
   172                     "outputs" : [("Q","BOOL","none")],
   170                     "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2.",
   173                     "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2.",
   171                     "generate" : generate_block},
   174                     "generate" : generate_block, "initialise" : initialise_block},
   172                 {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, 
   175                 {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, 
   173                     "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")], 
   176                     "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")], 
   174                     "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")],
   177                     "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")],
   175                     "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.",
   178                     "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.",
   176                     "generate" : generate_block}
   179                     "generate" : generate_block, "initialise" : initialise_block}
   177                 ]},
   180                 ]},
   178              ]
   181              ]
   179              
   182              
   180 PluginTypes = []
   183 PluginTypes = []
   181 
   184 
   493                 Standard_Functions_Decl.append(Current_section)
   496                 Standard_Functions_Decl.append(Current_section)
   494                 Function_decl_list = []
   497                 Function_decl_list = []
   495             if Current_section:
   498             if Current_section:
   496                 Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
   499                 Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
   497                 Function_decl["generate"] = generate_block
   500                 Function_decl["generate"] = generate_block
       
   501                 Function_decl["initialise"] = lambda x,y:[]
   498                 baseinputnumber = int(Function_decl.get("baseinputnumber",1))
   502                 baseinputnumber = int(Function_decl.get("baseinputnumber",1))
   499                 Function_decl["baseinputnumber"] = baseinputnumber
   503                 Function_decl["baseinputnumber"] = baseinputnumber
   500                 for param, value in Function_decl.iteritems():
   504                 for param, value in Function_decl.iteritems():
   501                     if param in translate:
   505                     if param in translate:
   502                         Function_decl[param] = translate[param](value)
   506                         Function_decl[param] = translate[param](value)