lpcmanager

d5d9d419e981
Parents 870e9d7ec9c0
Children 16a954b017af
Exporter is invisible and added option to enable it.
--- a/LPCManager.py Fri Mar 31 12:37:51 2017 +0200
+++ b/LPCManager.py Fri Mar 31 13:09:51 2017 +0200
@@ -11,6 +11,7 @@
import __builtin__
from types import TupleType, StringType, UnicodeType
+
_lpcmanager_path = os.path.split(__file__)[0]
_dist_folder = os.path.split(sys.path[0])[0]
_beremiz_folder = os.path.join(_dist_folder, "beremiz")
@@ -75,10 +76,6 @@
InstallLocalRessources(_beremiz_folder)
- from util.BitmapLibrary import AddBitmapFolder
- AddBitmapFolder(os.path.join(_lpcmanager_path, "images"))
-
-
_lpcmanager_path = os.path.split(__file__)[0]
import features
from POULibrary import POULibrary
@@ -412,7 +409,6 @@
# slave.BaseParams.setEnabled(False)
slave.CTNRequestSave()
-
# -------------------------------------------------------------------------------
# LPCProjectController Class
# -------------------------------------------------------------------------------
@@ -1118,23 +1114,6 @@
def _Transfer(self):
if self.OnlineMode == "NORMAL":
- MD5 = self.GetLastBuildMD5()
- extrafiles = []
- for extrafilespath in [self._getExtraFilesPath(),
- self._getProjectFilesPath()]:
- extrafiles.extend(
- [(name, open(os.path.join(extrafilespath, name),
- 'rb').read()) \
- for name in os.listdir(extrafilespath)])
- builder = self.GetBuilder()
- if builder is not None:
- data = builder.GetBinaryCode()
- if data is not None:
- if not self._connector.NewPLC(MD5, data, extrafiles):
- dialog = wx.MessageDialog(self.AppFrame, "You must stop the PLC before transfer. Do you want to stop it now and transfer?", style=wx.YES_NO|wx.CENTRE)
- if dialog.ShowModal() == wx.ID_YES:
- self._Stop()
-
ProjectController._Transfer(self)
return
if self.CurrentMode is None and self.OnlineMode != "OFF":
@@ -1337,6 +1316,15 @@
class LPCBeremiz(Beremiz):
def _init_coll_FileMenu_Items(self, parent):
+ config = wx.ConfigBase.Get()
+ export = str(config.Read("Exporter"))
+ if export == "":
+ config.Write("Exporter", '0')
+ export = '0'
+ if export == '1':
+ export = True
+ else:
+ export = False
AppendMenu(parent, help='', id=wx.ID_SAVE,
kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
AppendMenu(parent, help='', id=wx.ID_CLOSE,
@@ -1349,9 +1337,10 @@
AppendMenu(parent, help='', id=wx.ID_PRINT,
kind=wx.ITEM_NORMAL, text=_(u'Print'))
parent.AppendSeparator()
- AppendMenu(parent, help='', id=ID_EXPORT,
- kind=wx.ITEM_NORMAL, text=_(u'Export'))
- parent.AppendSeparator()
+ if export:
+ AppendMenu(parent, help='', id=ID_EXPORT,
+ kind=wx.ITEM_NORMAL, text=_(u'Export'))
+ parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_EXIT,
kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
@@ -1360,7 +1349,8 @@
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
- self.Bind(wx.EVT_MENU, lambda event: VariableWriter(self, event, self.CTR.ProjectPath), id=ID_EXPORT)
+ if export:
+ self.Bind(wx.EVT_MENU, lambda event: VariableWriter(self, event, self.CTR.ProjectPath), id=ID_EXPORT)
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
self.AddToMenuToolBar([(wx.ID_SAVE, "save", _(u'Save'), None),
--- a/VariableExporter.py Fri Mar 31 12:37:51 2017 +0200
+++ b/VariableExporter.py Fri Mar 31 13:09:51 2017 +0200
@@ -15,18 +15,19 @@
parent.Controler.logger.write(_("Exporting...\n"))
modbus_list = []
modbus_dict = {}
+ setting_list = []
+ command_list = []
+ bit_dict = {}
program_name = ""
program_type = ""
with open(path + "\plc.xml") as infile:
for line in infile:
if "<pou" in line:
start_program = line.find("name")
- program_name = ""
if start_program != -1:
end_program = line[start_program:].find(" ")
program_name = line[start_program + 6:start_program + end_program - 1]
start_type = line.find("pouType")
- program_type = ""
if start_type != -1:
end_type = line[start_type:].find("\"")
program_type = line[start_type + 9:start_type + end_type + 8]
@@ -39,6 +40,47 @@
address = target.split("_")[-1]
modbus_list.append(name)
modbus_dict[name] = [target, address, program_name, program_type]
+ elif ":= WORD_TO_UINT(" in line and not "UINT_TO_WORD" in line:
+ idx = line.find(":= WORD_TO_UINT(")
+ end = line[idx:].find(")")
+ name = line[idx + len(":= WORD_TO_UINT("):idx + end]
+ space = line.find(" ")
+ target = line[:space]
+ address = name.split("_")[-1]
+ setting_list.append([target, "", "", "", "", name, address])
+ elif ":= WORD_TO_BOOL(" in line:
+ idx = line.find(":= WORD_TO_BOOL(")
+ end = line[idx + len(":= WORD_TO_BOOL("):].find(" ")
+ name = line[idx + len(":= WORD_TO_BOOL("):idx + len(":= WORD_TO_BOOL(") + end]
+ target = line[:idx].strip()
+ address = name.split("_")[-1]
+ bit_start = line.find(" N := ")
+ bit_end = line[bit_start:].find(")")
+ bit = line[bit_start + len(" N := "):bit_start + bit_end]
+ command_list.append([target, "", "", "", "", name, address+"."+bit])
+ elif ":= BOOL_TO_WORD(" in line:
+ idx = line.find(":= BOOL_TO_WORD(") + len(":= BOOL_TO_WORD(")
+ if "UINT_TO_BOOL(" in line[idx:]:
+ idx += len("UINT_TO_BOOL")
+ end = line[idx:].find(")")
+ else:
+ end = line[idx:].find(")")
+ name = line[idx:idx+end]
+ if "(*" in line:
+ target_start = len("(*")
+ else:
+ target_start = 0
+ target_end = line.find(" := ")
+ target = line[target_start:target_end].strip()
+ address = target.split("_")[-1]
+ if " N := " in line:
+ bit_start = line.find(" N := ")
+ bit_end = line[bit_start:].find(")")
+ bit = line[bit_start + len(" N := "):bit_start + bit_end]
+ bit_dict[name] = [target, address+"."+bit, program_name, program_type]
+ else:
+ bit_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))]
@@ -95,13 +137,24 @@
if len(curr_variable) > 0:
if name in modbus_list:
curr_variable += modbus_dict[name]
+ elif name in bit_dict:
+ curr_variable += bit_dict[name]
else:
- curr_variable += ["", "", ""]
+ curr_variable += ["", "", "", ""]
if curr_variable != []:
variables.append(curr_variable)
-
- with open(export, "wb") as f:
- writer = csv.writer(f)
- writer.writerows(variables)
- parent.Controler.logger.write(_("Export completed successfully.\n"))
\ No newline at end of file
+ try:
+ with open(export, "wb") as f:
+ writer = csv.writer(f)
+ writer.writerows(variables)
+ writer = csv.writer(f)
+ writer.writerows([""])
+ writer.writerows(setting_list)
+ writer.writerows([""])
+ writer.writerows(command_list)
+ parent.Controler.logger.write(_("Export completed successfully.\n"))
+ except IOError:
+ dialog = wx.MessageDialog(parent, "File is oppened in another program. Please close it before exporting.", style= wx.OK | wx.ICON_EXCLAMATION)
+ dialog.ShowModal()
+ parent.Controler.logger.write_error(_("Export failed.\n"))
\ No newline at end of file