40 port = int(args[2]) |
40 port = int(args[2]) |
41 except: |
41 except: |
42 usage() |
42 usage() |
43 sys.exit() |
43 sys.exit() |
44 |
44 |
45 app = wx.PySimpleApp() |
45 if os.path.exists("LPC_DEBUG"): |
|
46 __builtins__.BMZ_DBG = True |
|
47 else : |
|
48 __builtins__.BMZ_DBG = False |
|
49 |
|
50 app = wx.PySimpleApp(redirect=BMZ_DBG) |
46 app.SetAppName('beremiz') |
51 app.SetAppName('beremiz') |
47 wx.InitAllImageHandlers() |
52 wx.InitAllImageHandlers() |
48 |
53 |
49 # Import module for internationalization |
54 # Import module for internationalization |
50 import gettext |
55 import gettext |
368 os.makedirs(dstpath) |
373 os.makedirs(dstpath) |
369 mycopytree(srcpath, dstpath) |
374 mycopytree(srcpath, dstpath) |
370 elif os.path.isfile(srcpath): |
375 elif os.path.isfile(srcpath): |
371 shutil.copy2(srcpath, dstpath) |
376 shutil.copy2(srcpath, dstpath) |
372 |
377 |
373 [SIMULATION_MODE, TRANSFER_MODE] = range(2) |
378 [SIMULATION_MODE, ONLINE_MODE] = range(2) |
374 |
379 |
375 class LPCPluginsRoot(PluginsRoot): |
380 class LPCPluginsRoot(PluginsRoot): |
376 |
381 |
377 PluginMethods = [ |
382 PluginMethods = [ |
378 {"bitmap" : opjimg("Debug"), |
383 {"bitmap" : opjimg("Debug"), |
487 status = "" |
492 status = "" |
488 self.logger.write(_("PLC is %s\n")%status) |
493 self.logger.write(_("PLC is %s\n")%status) |
489 |
494 |
490 if self.StatusTimer and not self.StatusTimer.IsRunning(): |
495 if self.StatusTimer and not self.StatusTimer.IsRunning(): |
491 # Start the status Timer |
496 # Start the status Timer |
492 self.StatusTimer.Start(milliseconds=500, oneShot=False) |
497 self.StatusTimer.Start(milliseconds=1000, oneShot=False) |
493 |
498 |
494 if self.previous_plcstate=="Started": |
499 if self.previous_plcstate=="Started": |
495 if self.DebugAvailable() and self.GetIECProgramsAndVariables(): |
500 if self.DebugAvailable() and self.GetIECProgramsAndVariables(): |
496 self.logger.write(_("Debug connect matching running PLC\n")) |
501 self.logger.write(_("Debug connect matching running PLC\n")) |
497 self._connect_debug() |
502 #TODO re-enable |
|
503 #self._connect_debug() |
498 else: |
504 else: |
499 self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n")) |
505 self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n")) |
500 |
506 |
501 elif self.StatusTimer and self.StatusTimer.IsRunning(): |
507 elif self.StatusTimer and self.StatusTimer.IsRunning(): |
502 self.StatusTimer.Stop() |
508 self.StatusTimer.Stop() |
503 |
509 |
504 if self.CurrentMode == TRANSFER_MODE: |
510 if self.CurrentMode == ONLINE_MODE: |
505 |
511 |
506 if self.OnlineMode == "BOOTLOADER": |
512 if self.OnlineMode == "BOOTLOADER": |
507 self.BeginTransfer() |
513 self.BeginTransfer() |
508 |
514 |
509 elif self.OnlineMode == "APPLICATION": |
515 elif self.OnlineMode == "APPLICATION": |
605 ("_Run", True), |
611 ("_Run", True), |
606 ("_Stop", False), |
612 ("_Stop", False), |
607 ("_build", True), |
613 ("_build", True), |
608 ("_Transfer", True)], |
614 ("_Transfer", True)], |
609 "Connected" : [("_Simulate", not simulating), |
615 "Connected" : [("_Simulate", not simulating), |
610 ("_Run", False), |
616 ("_Run", True), |
611 ("_Stop", simulating), |
617 ("_Stop", simulating), |
612 ("_build", True), |
618 ("_build", True), |
613 ("_Transfer", True)], |
619 ("_Transfer", True)], |
614 "Disconnected" :[("_Simulate", not simulating), |
620 "Disconnected" :[("_Simulate", not simulating), |
615 ("_Run", False), |
621 ("_Run", False), |
778 # Check remote target PLC correspondance to that md5 |
784 # Check remote target PLC correspondance to that md5 |
779 if MD5 is not None and self.LPCConnector.MatchMD5(MD5): |
785 if MD5 is not None and self.LPCConnector.MatchMD5(MD5): |
780 # warns controller that program match |
786 # warns controller that program match |
781 self.ProgramTransferred() |
787 self.ProgramTransferred() |
782 |
788 |
|
789 def GetLastBuildMD5(self): |
|
790 builder=self.GetBuilder() |
|
791 if builder is not None: |
|
792 return builder.GetBinaryCodeMD5(self.OnlineMode) |
|
793 else: |
|
794 return None |
|
795 |
783 def _Transfer(self): |
796 def _Transfer(self): |
784 if self.CurrentMode is None and self.OnlineMode != "OFF": |
797 if self.CurrentMode is None and self.OnlineMode != "OFF": |
785 self.CurrentMode = TRANSFER_MODE |
798 self.CurrentMode = ONLINE_MODE |
786 |
799 |
787 PluginsRoot._build(self) |
800 PluginsRoot._build(self) |
788 |
801 |
789 ID_ABORTTRANSFERTIMER = wx.NewId() |
802 ID_ABORTTRANSFERTIMER = wx.NewId() |
790 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER) |
803 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER) |
811 |
824 |
812 self.CurrentMode = None |
825 self.CurrentMode = None |
813 self.AbortTransferTimer.Stop() |
826 self.AbortTransferTimer.Stop() |
814 self.AbortTransferTimer = None |
827 self.AbortTransferTimer = None |
815 event.Skip() |
828 event.Skip() |
|
829 |
|
830 def _Run(self): |
|
831 """ |
|
832 Start PLC |
|
833 """ |
|
834 if self.GetIECProgramsAndVariables(): |
|
835 self._connector.StartPLC() |
|
836 self.logger.write(_("Starting PLC\n")) |
|
837 #TODO re-enable |
|
838 #self._connect_debug() |
|
839 else: |
|
840 self.logger.write_error(_("Couldn't start PLC !\n")) |
|
841 self.UpdateMethodsFromPLCStatus() |
816 |
842 |
817 #------------------------------------------------------------------------------- |
843 #------------------------------------------------------------------------------- |
818 # LPCBeremiz Class |
844 # LPCBeremiz Class |
819 #------------------------------------------------------------------------------- |
845 #------------------------------------------------------------------------------- |
820 lpcberemiz_cmd=None |
846 lpcberemiz_cmd=None |
1088 self.Buffer += self.socket.recv(2048) |
1114 self.Buffer += self.socket.recv(2048) |
1089 idx = self.Buffer.find("\n") |
1115 idx = self.Buffer.find("\n") |
1090 if idx != -1: |
1116 if idx != -1: |
1091 line = self.Buffer[:idx+1] |
1117 line = self.Buffer[:idx+1] |
1092 self.Buffer = self.Buffer[idx+1:] |
1118 self.Buffer = self.Buffer[idx+1:] |
|
1119 if BMZ_DBG: |
|
1120 print "command >"+line |
1093 return line |
1121 return line |
1094 return "" |
1122 return "" |
1095 |
1123 |
1096 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
1124 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
1097 def write(self, s, style = None): |
1125 def write(self, s, style = None): |
1130 wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
1158 wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
1131 wx_eval_lock.acquire() |
1159 wx_eval_lock.acquire() |
1132 return eval_res |
1160 return eval_res |
1133 |
1161 |
1134 # Command log for debug, for viewing from wxInspector |
1162 # Command log for debug, for viewing from wxInspector |
1135 __builtins__.cmdlog = [] |
1163 if BMZ_DBG: |
1136 #cmdlogf=open("bmzcmdlog.txt","w") |
1164 __builtins__.cmdlog = [] |
1137 |
1165 |
1138 class LPCBeremiz_Cmd(cmd.Cmd): |
1166 class LPCBeremiz_Cmd(cmd.Cmd): |
1139 |
1167 |
1140 prompt = "" |
1168 prompt = "" |
1141 RefreshTimer = None |
1169 RefreshTimer = None |
1419 except: |
1447 except: |
1420 self.Log.write("Error: Invalid value for argument %d\n" % (num + 1)) |
1448 self.Log.write("Error: Invalid value for argument %d\n" % (num + 1)) |
1421 sys.stdout.flush() |
1449 sys.stdout.flush() |
1422 return |
1450 return |
1423 |
1451 |
1424 #cmdlogf.write(str((function,line))+'\n') |
|
1425 #cmdlogf.flush() |
|
1426 |
|
1427 func = getattr(self, function) |
1452 func = getattr(self, function) |
1428 res = evaluator(func,*args) |
1453 res = evaluator(func,*args) |
1429 |
1454 |
1430 # Keep log for debug |
1455 if BMZ_DBG: |
1431 #cmdlogf.write("--->"+str(res)+'\n') |
1456 cmdlog.append((function,line,res)) |
1432 #cmdlogf.flush() |
1457 if len(cmdlog) > 100: #prevent debug log to grow too much |
1433 |
1458 cmdlog.pop(0) |
1434 cmdlog.append((function,line,res)) |
|
1435 if len(cmdlog) > 100: #prevent debug log to grow too much |
|
1436 cmdlog.pop(0) |
|
1437 |
1459 |
1438 if isinstance(res, (StringType, UnicodeType)): |
1460 if isinstance(res, (StringType, UnicodeType)): |
1439 self.Log.write(res) |
1461 self.Log.write(res) |
1440 return False |
1462 return False |
1441 else: |
1463 else: |