55 |
55 |
56 def Generate_C(self, buildpath, varlist, IECCFLAGS): |
56 def Generate_C(self, buildpath, varlist, IECCFLAGS): |
57 global hmi_tree_root, on_hmitree_update, maxConnectionsTotal |
57 global hmi_tree_root, on_hmitree_update, maxConnectionsTotal |
58 |
58 |
59 already_found_watchdog = False |
59 already_found_watchdog = False |
|
60 found_SVGHMI_instance = False |
60 for CTNChild in self.GetCTR().IterChildren(): |
61 for CTNChild in self.GetCTR().IterChildren(): |
61 if isinstance(CTNChild, SVGHMI): |
62 if isinstance(CTNChild, SVGHMI): |
|
63 found_SVGHMI_instance = True |
62 # collect maximum connection total for all svghmi nodes |
64 # collect maximum connection total for all svghmi nodes |
63 maxConnectionsTotal += CTNChild.GetParamsAttributes("SVGHMI.MaxConnections")["value"] |
65 maxConnectionsTotal += CTNChild.GetParamsAttributes("SVGHMI.MaxConnections")["value"] |
64 |
66 |
65 # spot watchdog abuse |
67 # spot watchdog abuse |
66 if CTNChild.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"]: |
68 if CTNChild.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"]: |
67 if already_found_watchdog: |
69 if already_found_watchdog: |
68 self.FatalError("SVGHMI: Only one watchdog enabled HMI allowed") |
70 self.FatalError("SVGHMI: Only one watchdog enabled HMI allowed") |
69 already_found_watchdog = True |
71 already_found_watchdog = True |
|
72 |
|
73 if not found_SVGHMI_instance: |
|
74 self.FatalError("SVGHMI : Library is selected but not used. Please either deselect it in project config or add a SVGHMI node to project.") |
70 |
75 |
71 |
76 |
72 """ |
77 """ |
73 PLC Instance Tree: |
78 PLC Instance Tree: |
74 prog0 |
79 prog0 |
114 derived = v["derived"] |
119 derived = v["derived"] |
115 if derived == "HMI_NODE": |
120 if derived == "HMI_NODE": |
116 hmi_tree_root = HMITreeNode(path, "", derived, v["type"], v["vartype"], v["C_path"]) |
121 hmi_tree_root = HMITreeNode(path, "", derived, v["type"], v["vartype"], v["C_path"]) |
117 hmi_types_instances.pop(i) |
122 hmi_types_instances.pop(i) |
118 break |
123 break |
119 |
|
120 if hmi_tree_root is None: |
|
121 self.FatalError("SVGHMI : Library is selected but not used. Please either deselect it in project config or add a SVGHMI node to project.") |
|
122 |
124 |
123 # deduce HMI tree from PLC HMI_* instances |
125 # deduce HMI tree from PLC HMI_* instances |
124 for v in hmi_types_instances: |
126 for v in hmi_types_instances: |
125 path = v["IEC_path"].split(".") |
127 path = v["IEC_path"].split(".") |
126 # ignores variables starting with _TMP_ |
128 # ignores variables starting with _TMP_ |
476 oldt, m = self.times_msgs[k] |
478 oldt, m = self.times_msgs[k] |
477 self.indent = self.indent - 1 |
479 self.indent = self.indent - 1 |
478 self.GetCTRoot().logger.write(" "*self.indent + "... finished in %.3fs\n"%(t - oldt)) |
480 self.GetCTRoot().logger.write(" "*self.indent + "... finished in %.3fs\n"%(t - oldt)) |
479 |
481 |
480 def get_SVGHMI_options(self): |
482 def get_SVGHMI_options(self): |
481 view_name = self.BaseParams.getName() |
483 name = self.BaseParams.getName() |
482 port = self.GetParamsAttributes("SVGHMI.Port")["value"] |
484 port = self.GetParamsAttributes("SVGHMI.Port")["value"] |
483 interface = self.GetParamsAttributes("SVGHMI.Interface")["value"] |
485 interface = self.GetParamsAttributes("SVGHMI.Interface")["value"] |
484 path = self.GetParamsAttributes("SVGHMI.Path")["value"].format(name=view_name) |
486 path = self.GetParamsAttributes("SVGHMI.Path")["value"].format(name=name) |
485 if path and path[0]=='/': |
487 if path and path[0]=='/': |
486 path = path[1:] |
488 path = path[1:] |
487 enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"] |
489 enable_watchdog = self.GetParamsAttributes("SVGHMI.EnableWatchdog")["value"] |
488 url="http://"+interface+("" if port==80 else (":"+str(port)) |
490 url="http://"+interface+("" if port==80 else (":"+str(port)) |
489 ) + (("/"+path) if path else "" |
491 ) + (("/"+path) if path else "" |
490 ) + ("#watchdog" if enable_watchdog else "") |
492 ) + ("#watchdog" if enable_watchdog else "") |
491 |
493 |
492 return dict( |
494 return dict( |
493 view_name=view_name, |
495 name=name, |
494 port=port, |
496 port=port, |
495 interface=interface, |
497 interface=interface, |
496 path=path, |
498 path=path, |
497 enable_watchdog=enable_watchdog, |
499 enable_watchdog=enable_watchdog, |
498 url=url) |
500 url=url) |
499 |
501 |
500 def CTNGenerate_C(self, buildpath, locations): |
502 def CTNGenerate_C(self, buildpath, locations): |
|
503 global hmi_tree_root |
|
504 |
|
505 if hmi_tree_root is None: |
|
506 self.FatalError("SVGHMI : Library is not selected. Please select it in project config.") |
501 |
507 |
502 location_str = "_".join(map(str, self.GetCurrentLocation())) |
508 location_str = "_".join(map(str, self.GetCurrentLocation())) |
503 svghmi_options = self.get_SVGHMI_options() |
509 svghmi_options = self.get_SVGHMI_options() |
504 |
510 |
505 svgfile = self._getSVGpath() |
511 svgfile = self._getSVGpath() |
560 try: |
566 try: |
561 self.ProgressStart("xslt", "XSLT transform") |
567 self.ProgressStart("xslt", "XSLT transform") |
562 result = transform.transform(svgdom) # , profile_run=True) |
568 result = transform.transform(svgdom) # , profile_run=True) |
563 self.ProgressEnd("xslt") |
569 self.ProgressEnd("xslt") |
564 except XSLTApplyError as e: |
570 except XSLTApplyError as e: |
565 self.FatalError("SVGHMI " + svghmi_options["view_name"] + ": " + e.message) |
571 self.FatalError("SVGHMI " + svghmi_options["name"] + ": " + e.message) |
566 finally: |
572 finally: |
567 for entry in transform.get_error_log(): |
573 for entry in transform.get_error_log(): |
568 message = "SVGHMI: "+ entry.message + "\n" |
574 message = "SVGHMI: "+ entry.message + "\n" |
569 self.GetCTRoot().logger.write_warning(message) |
575 self.GetCTRoot().logger.write_warning(message) |
570 |
576 |
619 |
625 |
620 srv = svghmi_servers.get("{interface}:{port}", None) |
626 srv = svghmi_servers.get("{interface}:{port}", None) |
621 if srv is not None: |
627 if srv is not None: |
622 svghmi_root, svghmi_listener, path_list = srv |
628 svghmi_root, svghmi_listener, path_list = srv |
623 if '{path}' in path_list: |
629 if '{path}' in path_list: |
624 raise Exception("SVGHMI {view_name}: path {path} already used on {interface}:{port}") |
630 raise Exception("SVGHMI {name}: path {path} already used on {interface}:{port}") |
625 else: |
631 else: |
626 svghmi_root = Resource() |
632 svghmi_root = Resource() |
627 factory = HMIWebSocketServerFactory() |
633 factory = HMIWebSocketServerFactory() |
628 factory.setProtocolOptions(maxConnections={maxConnections}) |
634 factory.setProtocolOptions(maxConnections={maxConnections}) |
629 |
635 |
647 svghmi_watchdog = Watchdog( |
653 svghmi_watchdog = Watchdog( |
648 {watchdog_initial}, |
654 {watchdog_initial}, |
649 {watchdog_interval}, |
655 {watchdog_interval}, |
650 svghmi_{location}_watchdog_trigger) |
656 svghmi_{location}_watchdog_trigger) |
651 else: |
657 else: |
652 raise Exception("SVGHMI {view_name}: only one watchdog allowed") |
658 raise Exception("SVGHMI {name}: only one watchdog allowed") |
653 |
659 |
654 |
660 |
655 def _runtime_{location}_svghmi_stop(): |
661 def _runtime_{location}_svghmi_stop(): |
656 global svghmi_watchdog, svghmi_servers |
662 global svghmi_watchdog, svghmi_servers |
657 |
663 |