def VariableWriter(parent, event, path):
FileDialog = wx.FileDialog(parent, "Save CSV file", "", "", "CSV files (*.csv)|*.csv",
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if FileDialog.ShowModal() == wx.ID_OK:
if FileDialog.GetPath()[-4:] == ".csv":
export = FileDialog.GetPath()
export = FileDialog.GetPath() + ".csv"
parent.Controler.logger.write(_("Exporting...\n"))
with open(path + "\plc.xml") as infile:
start_program = line.find("name")
end_program = line[start_program:].find(" ")
program_name = line[start_program + 6:start_program + end_program - 1]
start_type = line.find("pouType")
end_type = line[start_type:].find("\"")
program_type = line[start_type + 9:start_type + end_type + 8]
if ":= UINT_TO_WORD(" in line:
idx = line.find(":= UINT_TO_WORD(")
end = line[idx:].find(")")
name = line[idx + len(":= UINT_TO_WORD("):idx + end]
address = target.split("_")[-1]
modbus_dict[name] = [target, address, program_name, program_type]
dir_list = [os.path.join(path, o) for o in os.listdir(path) if os.path.isdir(os.path.join(path, o))]
py_directories.append(dir)
["NAME", "TYPE", "GROUP", "SUBGROUP", "TYPE OF VARIABLE", "MODBUS NAME", "MODBUS ADDRESS", "PROGRAM NAME",
for dir in py_directories:
with open(dir + "\pyfile.xml") as infile:
idx_name = line.find("name")
end_name = line[idx_name:].find(" ")
name = line[idx_name + 6:idx_name + end_name - 1]
curr_variable.append(name)
idx_type = line.find("type")
end_type = line[idx_type:].find(" ")
type = line[idx_type + 6:idx_type + end_type - 1]
group = dir.split("\\")[-1].split("@")[0]
if len(curr_variable) > 0:
curr_variable.append(type)
curr_variable.append(group)
idx_opts = line.find("opts")
end_opts = line[idx_opts + 6:].find("\"")
opts = line[idx_opts + 6: idx_opts + end_opts + 6]
options = opts.split(" ")
if o in ["Session", "Alarm", "Static"]:
idx_subgroup = o.find("subgroup")
subgroup = o[idx_subgroup + 9:]
if len(curr_variable) > 0:
curr_variable.append(subgroup)
curr_variable.append(o_type)
if len(curr_variable) > 0:
curr_variable += modbus_dict[name]
curr_variable += ["", "", ""]
variables.append(curr_variable)
with open(export, "wb") as f:
writer.writerows(variables)
parent.Controler.logger.write(_("Export completed successfully.\n"))