777 |
777 |
778 def ApplyOnlineMode(self): |
778 def ApplyOnlineMode(self): |
779 if self.CurrentMode != SIMULATION_MODE: |
779 if self.CurrentMode != SIMULATION_MODE: |
780 self.KillDebugThread() |
780 self.KillDebugThread() |
781 |
781 |
782 self._connector = self.LPCConnector |
782 self._SetConnector(self.LPCConnector) |
783 |
783 |
784 # Init with actual PLC status and print it |
784 # Init with actual PLC status and print it |
785 self.UpdateMethodsFromPLCStatus() |
785 self.UpdateMethodsFromPLCStatus() |
786 |
786 |
787 if self.LPCConnector is not None and self.OnlineMode == "APPLICATION": |
787 if self.LPCConnector is not None and self.OnlineMode == "APPLICATION": |
915 |
915 |
916 ############# Real PLC object access ############# |
916 ############# Real PLC object access ############# |
917 def UpdateMethodsFromPLCStatus(self): |
917 def UpdateMethodsFromPLCStatus(self): |
918 # Get PLC state : Running or Stopped |
918 # Get PLC state : Running or Stopped |
919 # TODO : use explicit status instead of boolean |
919 # TODO : use explicit status instead of boolean |
|
920 simulating = self.CurrentMode == SIMULATION_MODE |
920 if self.OnlineMode == "OFF": |
921 if self.OnlineMode == "OFF": |
|
922 if simulating: |
|
923 status, log_count = self._connector.GetPLCstatus() |
|
924 self.UpdatePLCLog(log_count) |
921 status = "Disconnected" |
925 status = "Disconnected" |
922 elif self.OnlineMode == "BOOTLOADER": |
926 elif self.OnlineMode == "BOOTLOADER": |
923 status = "Connected" |
927 status = "Connected" |
924 else: |
928 else: |
925 if self._connector is not None: |
929 if self._connector is not None: |
926 status, log_count = self._connector.GetPLCstatus() |
930 status, log_count = self._connector.GetPLCstatus() |
927 self.UpdatePLCLog(log_count) |
931 if status == "Disconnected": |
|
932 self._SetConnector(None) |
|
933 else: |
|
934 self.UpdatePLCLog(log_count) |
928 else: |
935 else: |
929 status = "Disconnected" |
936 status = "Disconnected" |
930 if self.previous_plcstate != status or self.previous_mode != self.CurrentMode: |
937 if self.previous_plcstate != status or self.previous_mode != self.CurrentMode: |
931 simulating = self.CurrentMode == SIMULATION_MODE |
|
932 for args in { |
938 for args in { |
933 "Started" : [("_Simulate", False), |
939 "Started" : [("_Simulate", False), |
934 ("_Run", False), |
940 ("_Run", False), |
935 ("_Stop", True), |
941 ("_Stop", True), |
936 ("_Build", True), |
942 ("_Build", True), |
1055 """ |
1061 """ |
1056 self.CurrentMode = SIMULATION_MODE |
1062 self.CurrentMode = SIMULATION_MODE |
1057 |
1063 |
1058 uri = "LOCAL://" |
1064 uri = "LOCAL://" |
1059 try: |
1065 try: |
1060 self._connector = connectors.ConnectorFactory(uri, self) |
1066 self._SetConnector(connectors.ConnectorFactory(uri, self)) |
1061 except Exception, msg: |
1067 except Exception, msg: |
1062 self.logger.write_error(_("Exception while connecting %s!\n")%uri) |
1068 self.logger.write_error(_("Exception while connecting %s!\n")%uri) |
1063 self.logger.write_error(traceback.format_exc()) |
1069 self.logger.write_error(traceback.format_exc()) |
1064 |
1070 |
1065 # Did connection success ? |
1071 # Did connection success ? |