plcopen/structures.py
changeset 1283 f3cfe1ff917e
parent 1239 d1f6ea56555d
child 1297 cd639725fba5
equal deleted inserted replaced
1282:f427352f9727 1283:f3cfe1ff917e
   248     - The name
   248     - The name
   249     - The data type
   249     - The data type
   250     - The default modifier which can be "none", "negated", "rising" or "falling"
   250     - The default modifier which can be "none", "negated", "rising" or "falling"
   251 """
   251 """
   252 
   252 
   253 BlockTypes = [{"name" : _("Standard function blocks"), "list":
   253 StdBlckLst = [{"name" : _("Standard function blocks"), "list":
   254                [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
   254                [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
   255                     "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
   255                     "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
   256                     "outputs" : [("Q1","BOOL","none")],
   256                     "outputs" : [("Q1","BOOL","none")],
   257                     "comment" : _("SR bistable\nThe SR bistable is a latch where the Set dominates."),
   257                     "comment" : _("SR bistable\nThe SR bistable is a latch where the Set dominates."),
   258                     "generate" : generate_block, "initialise" : initialise_block},
   258                     "generate" : generate_block, "initialise" : initialise_block},
   661     
   661     
   662     return Standard_Functions_Decl
   662     return Standard_Functions_Decl
   663 
   663 
   664 std_decl = get_standard_funtions(csv_file_to_table(open(os.path.join(os.path.split(__file__)[0],"iec_std.csv"))))#, True)
   664 std_decl = get_standard_funtions(csv_file_to_table(open(os.path.join(os.path.split(__file__)[0],"iec_std.csv"))))#, True)
   665 
   665 
   666 BlockTypes.extend(std_decl)
   666 StdBlckLst.extend(std_decl)
   667 
   667 
   668 for section in BlockTypes: 
   668 # Dictionary to speedup block type fetching by name
       
   669 StdBlckDct = {}
       
   670 
       
   671 for section in StdBlckLst:
   669     for desc in section["list"]:
   672     for desc in section["list"]:
   670         words = desc["comment"].split('"')
   673         words = desc["comment"].split('"')
   671         if len(words) > 1:
   674         if len(words) > 1:
   672             desc["comment"] = words[1]
   675             desc["comment"] = words[1]
   673         desc["usage"] = (
   676         desc["usage"] = (
   674             "\n (" +
   677             "\n (" +
   675             str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["inputs"]]).strip("[]").replace("'",'') +
   678             str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["inputs"]]).strip("[]").replace("'",'') +
   676             " ) => (" +
   679             " ) => (" +
   677             str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["outputs"]]).strip("[]").replace("'",'') +
   680             str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["outputs"]]).strip("[]").replace("'",'') +
   678             " )")
   681             " )")
   679 
   682         BlkLst = StdBlckDct.setdefault(desc["name"],[])
       
   683         BlkLst.append((section["name"], desc))
   680 
   684 
   681 #-------------------------------------------------------------------------------
   685 #-------------------------------------------------------------------------------
   682 #                            Languages Keywords
   686 #                            Languages Keywords
   683 #-------------------------------------------------------------------------------
   687 #-------------------------------------------------------------------------------
   684 
   688 
   685 
   689 
   686 # Keywords for Pou Declaration
   690 # Keywords for Pou Declaration
   687 POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"]
   691 POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"]
   688 POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"]
   692 POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"]
   689 POU_KEYWORDS = ["EN", "ENO", "F_EDGE", "R_EDGE"] + POU_BLOCK_START_KEYWORDS + POU_BLOCK_END_KEYWORDS
   693 POU_KEYWORDS = ["EN", "ENO", "F_EDGE", "R_EDGE"] + POU_BLOCK_START_KEYWORDS + POU_BLOCK_END_KEYWORDS
   690 for category in BlockTypes:
   694 for category in StdBlckLst:
   691     for block in category["list"]:
   695     for block in category["list"]:
   692         if block["name"] not in POU_KEYWORDS:
   696         if block["name"] not in POU_KEYWORDS:
   693             POU_KEYWORDS.append(block["name"])
   697             POU_KEYWORDS.append(block["name"])
   694 
   698 
   695 
   699