diff --git a/FaultMonitor.py b/FaultMonitor.py index fb39801..c4dc8d5 100644 --- a/FaultMonitor.py +++ b/FaultMonitor.py @@ -31,12 +31,15 @@ class Controller: self.view = view self.timer = wx.Timer() self.timer.Bind(wx.EVT_TIMER, self.OnTimer) + self.mode = False pub.subscribe(self.getFaultInfo, 'fault_selected') pub.subscribe(self.startTimer, 'monitoring_started') pub.subscribe(self.stopTimer, 'monitoring_stopped') pub.subscribe(self.applyNetworkConfigs, 'apply_network_configs') pub.subscribe(self.resetNetworkConfigs, 'reset_network_configs') + pub.subscribe(self.resetPcsRemote, 'reset_pcs_remote') + pub.subscribe(self.checkSysOpMode, 'check_system_op_mode') def startTimer(self): self.timer.Start(2000) @@ -54,6 +57,16 @@ class Controller: self.sc.checkClose() self.sc = None + def resetPcsRemote(self): + if self.sc: + self.sc.resetPcs() + + def checkSysOpMode(self): + if self.sc: + self.mode = self.sc.checkOpMode() + a = "Auto" if self.mode else "Manual" + self.view.text_op_mode.SetValue(a) + def getFaultInfo(self, pos): y, x = pos fid = x + y*8 @@ -125,7 +138,7 @@ class MyFrame(FaultFrame): self.button_1.Enable() - def OnReset(self, event): + def OnReset(self, event=None): if not self.button_1.Enabled: return @@ -141,6 +154,12 @@ class MyFrame(FaultFrame): self.input_ip.Enable() self.input_refresh.Enable() + def OnButtonRemoteReset(self, event): + pub.sendMessage("reset_pcs_remote") + self.OnReset() + + def OnCheckSysOpMode(self, event): + pub.sendMessage("check_system_op_mode") # end of class MyFrame @@ -157,4 +176,6 @@ class MyApp(wx.App): if __name__ == "__main__": app = MyApp(0) app.MainLoop() - app.c.sc.checkClose() + + if app.c.sc: + app.c.sc.checkClose() diff --git a/FaultView.py b/FaultView.py index 757bc37..e0552b4 100644 --- a/FaultView.py +++ b/FaultView.py @@ -1,6 +1,6 @@ # -*- coding: UTF-8 -*- # -# generated by wxGlade 0.9.5 on Mon Feb 10 19:42:48 2020 +# generated by wxGlade 0.9.5 on Thu Feb 13 18:40:11 2020 # import wx @@ -24,8 +24,12 @@ class FaultFrame(wx.Frame): self.input_port = wx.TextCtrl(self, wx.ID_ANY, _("502")) self.input_uid = wx.TextCtrl(self, wx.ID_ANY, _("240")) self.input_refresh = wx.TextCtrl(self, wx.ID_ANY, _("2000")) - self.reset_button = wx.Button(self, wx.ID_ANY, _("Reset")) + self.reset_button = wx.Button(self, wx.ID_ANY, _("Reset Connection")) self.apply_button = wx.Button(self, wx.ID_ANY, _("Apply")) + self.rreset_button = wx.Button(self, wx.ID_ANY, _("Remote PCS Reset")) + self.some_button = wx.Button(self, wx.ID_STOP, "") + self.op_mode_button = wx.Button(self, wx.ID_ANY, _("System OP Mode")) + self.text_op_mode = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_READONLY) self.fault_grid = wx.grid.Grid(self, wx.ID_ANY, size=(1, 1)) self.button_1 = wx.ToggleButton(self, wx.ID_ANY, _("Start")) self.text_fault_doc = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_READONLY) @@ -36,6 +40,8 @@ class FaultFrame(wx.Frame): self.Bind(wx.EVT_BUTTON, self.OnReset, self.reset_button) self.Bind(wx.EVT_BUTTON, self.OnApply, self.apply_button) + self.Bind(wx.EVT_BUTTON, self.OnButtonRemoteReset, self.rreset_button) + self.Bind(wx.EVT_BUTTON, self.OnCheckSysOpMode, self.op_mode_button) self.Bind(wx.grid.EVT_GRID_CMD_CELL_LEFT_CLICK, self.OnFaultSelect, self.fault_grid) self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleMonitoring, self.button_1) # end wxGlade @@ -77,7 +83,7 @@ class FaultFrame(wx.Frame): sizer_1 = wx.BoxSizer(wx.HORIZONTAL) sizer_3 = wx.BoxSizer(wx.VERTICAL) sizer_2 = wx.BoxSizer(wx.HORIZONTAL) - sizer_4 = wx.GridSizer(5, 2, 0, 0) + sizer_4 = wx.GridSizer(7, 2, 0, 0) label_1 = wx.StaticText(self, wx.ID_ANY, _("IP Address")) sizer_4.Add(label_1, 0, 0, 0) sizer_4.Add(self.input_ip, 0, 0, 0) @@ -92,6 +98,10 @@ class FaultFrame(wx.Frame): sizer_4.Add(self.input_refresh, 0, 0, 0) sizer_4.Add(self.reset_button, 0, 0, 0) sizer_4.Add(self.apply_button, 0, 0, 0) + sizer_4.Add(self.rreset_button, 0, 0, 0) + sizer_4.Add(self.some_button, 0, 0, 0) + sizer_4.Add(self.op_mode_button, 0, 0, 0) + sizer_4.Add(self.text_op_mode, 0, 0, 0) sizer_1.Add(sizer_4, 1, wx.EXPAND, 0) sizer_2.Add(self.fault_grid, 0, wx.ALIGN_CENTER, 0) sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER, 0) @@ -111,6 +121,14 @@ class FaultFrame(wx.Frame): print("Event handler 'OnApply' not implemented!") event.Skip() + def OnButtonRemoteReset(self, event): # wxGlade: FaultFrame. + print("Event handler 'OnButtonRemoteReset' not implemented!") + event.Skip() + + def OnCheckSysOpMode(self, event): # wxGlade: FaultFrame. + print("Event handler 'OnCheckSysOpMode' not implemented!") + event.Skip() + def OnFaultSelect(self, event): # wxGlade: FaultFrame. print("Event handler 'OnFaultSelect' not implemented!") event.Skip() diff --git a/faultView.wxg b/faultView.wxg index 8473ff6..deb6b97 100644 --- a/faultView.wxg +++ b/faultView.wxg @@ -1,9 +1,9 @@ - + - 632, 556 + 558, 556 frame @@ -13,7 +13,7 @@ 0 wxEXPAND - 5 + 7 2 0 0 @@ -80,7 +80,7 @@ OnReset - + @@ -93,6 +93,44 @@ + + + 0 + + + OnButtonRemoteReset + + + + + + + 0 + + + ToggleMonitoring + + 1 + + + + + + 0 + + + OnCheckSysOpMode + + + + + + + 0 + + + + @@ -102,61 +140,41 @@ wxVERTICAL - + 0 wxALIGN_CENTER - - wxHORIZONTAL - - - 0 - wxALIGN_CENTER - - - OnFaultSelect - - 270, 270 - 1 - - A - B - C - D - E - F - G - H - - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - - 0 - 1 - 0 - 0 - 0 - wxGrid.wxGridSelectCells - - - - - 0 - wxALIGN_CENTER - - - ToggleMonitoring - - 1 - - - + + + OnFaultSelect + + 270, 270 + 1 + + A + B + C + D + E + F + G + H + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + + 0 + 1 + 0 + 0 + 0 + wxGrid.wxGridSelectCells diff --git a/stabiliti.py b/stabiliti.py index da83ab1..1005770 100644 --- a/stabiliti.py +++ b/stabiliti.py @@ -36,11 +36,21 @@ class StabilitiController(object): return configDict def reg2utc(self, timel, timeu): - return dt.utcfromtimestamp((timeu << 16) + timel) + return dt.fromtimestamp((timeu << 16) + timel) def reg2bits(self, reg): return bin(reg)[2:].zfill(16) + def resetPcs(self): + self.checkConnect() + self.client.write_single_register(266, 0x8000) + + def checkOpMode(self): + self.checkConnect() + val = self.client.read_holdingregisters(267, 1) + print (val) + return val[0] == 1 + def readFaultDetail(self, findex): if not (0<=findex<=63): return None