def convert_compile_load():
    # Comment this if don't wont to compile model again

    # ###################################################
    # # Convert the model
    converter = Converter("psim", netlist_path)
    tse_path = converter.convert_schema(compile_model=False)[0]
    cpd_path = tse_path[:-4] + " Target files\\" + tse_path.split("\\")[-1][:-4] + ".cpd"
    # Open the converted tse file
    model.load(tse_path)
    # Compile the model
    model.compile()
    ###################################################

    # Load to VHIL
    hil.load_model(file=cpd_path, offlineMode=False, vhil_device=vhil)
Exemple #2
0
def convert_xml2tse(create_psim_netxml):
    # Converts the psim xml netlist to tse
    netxml_path = create_psim_netxml[1]
    converter = Converter("psim", netxml_path)
    tse_path = converter.convert_schema(compile_model=False)[0]
    return tse_path
Exemple #3
0
def convert_slx2tse(slx_path):
    # Converts the Simulink .slx file to .tse
    converter = Converter("simulink", slx_path)
    tse_path = converter.convert_schema(compile_model=False)[0]
    return tse_path
Exemple #4
0
def convert_to_tse(source_file_format, input_file_path):
    converter = Converter(source_file_format, input_file_path)
    tse_path = converter.convert_schema(compile_model=False)[0]
    return tse_path
class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)

        self.converter = None
        self.input_file_path = ""

        self.device = "HIL 604"
        self.configuration_id = "1"

        self.config_dialog = None

        self.parent = parent
        self.parent.title(f"Typhoon HIL Model Converter {Converter.VERSION}")
        self.parent.iconbitmap(default=self.get_icon_path())

        self.file_path_label1 = tk.Label(self,
                                         background="#f0f0f5",
                                         text="Selected file path:",
                                         justify=tk.LEFT)
        self.file_path_label2 = tk.Label(self,
                                         wraplength=650,
                                         background="#f0f0f5",
                                         text="None")
        self.progress_bar = ttk.Progressbar(self,
                                            orient="horizontal",
                                            mode="determinate",
                                            length=650,
                                            maximum=100)
        self.progress_bar.grid(row=2, column=0)
        self.file_path_label1.grid(row=0, column=0)
        self.file_path_label2.grid(row=1, column=0)

        self.report_area = tk.Frame(self, height=30, width=85)

        self.report_text = tk.Text(self.report_area, state="disabled", padx=15)
        self.report_text.grid(row=0, column=0)
        self.report_area.grid(row=3, column=0, padx=15, pady=15, rowspan=100)

        self.config_btn = tk.Button(self,
                                    text="Set \nHIL \nconfiguration",
                                    width=15,
                                    command=self.on_config_btn_clicked)

        self.model_source_label1 = tk.Label(self,
                                            background="#f0f0f5",
                                            text="Model source:")
        self.model_source_cb = tk.ttk.Combobox(self,
                                               state="readonly",
                                               width=10)
        self.model_source_cb["values"] = ["PSIM", "Simulink"]

        self.model_source_cb.current(0)
        self.model_source_label1.grid(row=3, column=1)
        self.model_source_cb.grid(row=4, column=1)
        self.config_btn.grid(row=5, column=1)

        self.input_file_btn = tk.Button(self,
                                        text="Select \nmodel \nfile",
                                        width=15,
                                        command=self.on_input_file_btn_clicked)

        self.input_file_btn.grid(row=6, column=1, padx=10)

        self.convert_btn = tk.Button(self,
                                     text="Convert \nselected \nfile",
                                     width=15,
                                     state="disabled",
                                     command=self.on_convert_btn_clicked)

        self.convert_btn.grid(row=7, column=1)

    def on_input_file_btn_clicked(self):

        #TODO: this IF statement should be updated
        #      whenever new input parsers are added
        if self.model_source_cb.get() == "PSIM":
            filetypes = ("PSIM netlist (.xml)", "*.xml")
        else:
            filetypes = ("Simulink model (.slx)", "*.slx")

        path = askopenfilename(initialdir="/",
                               title="Select file",
                               filetypes=(filetypes, ))

        self.set_input_file_path(path)

    def on_config_btn_clicked(self):
        if self.config_dialog is not None:
            self.config_dialog.top.destroy()
        self.config_dialog = HILConfigDialog(self)
        self.wait_window(self.config_dialog.top)

    def on_convert_btn_clicked(self):
        self.progress_bar.config(value=20)
        source_type = self.model_source_cb.get()
        try:
            self.converter = \
                Converter(source_file_format=source_type,
                          input_file_path=self.input_file_path)
        except Exception as ex:
            self.progress_bar.config(value=0)
            self.report_text.config(state="normal")
            self.report_text.delete('1.0', tk.END)
            self.report_text.insert(
                tk.END, f"Invalid file selected for "
                f"{source_type} conversion.\n"
                f"Exception thrown: {ex}")
            self.report_text.config(state="disabled")
            return
        device = self.device.replace(" ", "")
        try:
            tse_path, compiled, report_path = \
                self.converter.convert_schema(device_id=device,
                                              config_id=self.configuration_id,
                                              compile_model=True)

        except SchApiException as ex:
            self.progress_bar.config(value=0)
            self.report_text.config(state="normal")
            self.report_text.delete('1.0', tk.END)
            self.report_text.insert(
                tk.END, "Error converting selected netlist."
                "Please check the validity of the file.")
            self.report_text.config(state="disabled")
            return
        self.progress_bar.config(value=100)
        with open(report_path, "r") as report:
            scrollbar = tk.Scrollbar(self.report_area,
                                     command=self.report_text.yview)
            scrollbar.grid(row=0, column=1, sticky="nsew")
            self.report_text.config(yscrollcommand=scrollbar.set)

            self.report_text.config(state="normal")
            self.report_text.delete('1.0', tk.END)
            valid_report = "--------------------------------\n"
            if compiled:
                valid_report += "Model has been compiled successfully."
            else:
                valid_report += "Model compilation failed."
            valid_report += "\n--------------------------------\n\n"
            self.report_text.insert(tk.END, valid_report)
            self.report_text.insert(tk.END, report.read())
            self.report_text.config(state="disabled")
        with open(self.converter.parser.detailed_log_path, "r") as log:
            log_text = log.read()
            # If any errors are present
            if log_text:
                self.report_text.config(state="normal")
                self.report_text.insert(
                    tk.END, "\n\nDetailed error log\n"
                    "--------------------------------\n")
                self.report_text.insert(tk.END, log_text)
                self.report_text.config(state="disabled")

    def set_input_file_path(self, path: str):
        if path != "":
            self.progress_bar.config(value=0)
            self.input_file_path = path
            self.convert_btn.config(state="normal")
            self.file_path_label2.config(text=path.replace("/", "\\"))

    def get_icon_path(self):
        return os.path.join(self.get_root_path(), "app", "resources",
                            "thil_icon.ico")

    def get_root_path(self):
        return os.path.split(
            os.path.abspath(
                os.path.join(os.path.realpath(__file__), '..', '..')))[0]
Exemple #6
0
                                 f"of the HIL device ."
                                 f"(default: {DEFAULT_CONFIG})",
                            required=False,
                            default=DEFAULT_CONFIG)

    arg_parser.add_argument("--compile",
                            help=f"Should the converted model "
                                 f"be compiled? Allowed values are True "
                                 f"or False (default: {DEFAULT_COMPILE})",
                            type=input_is_true,
                            required=False,
                            default=DEFAULT_COMPILE)

    args = arg_parser.parse_args()
    # All args' (Namespace class) attributes are dynamically added
    # and named by the add_argument method of the arg_parser.
    # The .model attribute holds the path to the input model (netlist) file
    if args.model is None:
        root = tkinter.Tk()
        root.resizable(width=False, height=False)
        MainApplication(root).grid(row=0, column=1)
        root.mainloop()
    else:
        converter = Converter(source_file_format=args.source,
                              input_file_path=args.model,
                              rule_file_path=args.rules)
        converter.convert_schema(device_id=args.device,
                                 config_id=args.config,
                                 compile_model=args.compile)
        print("Done. Check the report.txt file located in "
              "the source file's folder for more info.")