diff --git a/FaultMonitor.py b/FaultMonitor.py index 23b7464..4301f86 100644 --- a/FaultMonitor.py +++ b/FaultMonitor.py @@ -28,6 +28,11 @@ print('pubsub API version', pub.VERSION_API) pubsub.utils.notification.useNotifyByWriteFile(sys.stdout) +class WebRelay: + def __init__(self, n_relay=10): + self.n_relay = n_relay + self.relay_status = [False for i in range(self.n_relay)] + class Controller: def __init__(self, view): self.sc = None @@ -39,7 +44,6 @@ class Controller: self.mbclient = None - 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') @@ -49,6 +53,38 @@ class Controller: pub.subscribe(self.startSystemOp, "start_system_op_manual") pub.subscribe(self.stopSystemOp, "stop_system_op_manual") + pub.subscribe(self.turnRelayOn, "turn_relay_on") + pub.subscribe(self.turnRelayOff, "turn_relay_off") + + ''' +def WriteSingleCoil(self, startingAddress, value) + +Write single Coil to Server device (Function code 5) +startingAddress: Coil to be written +value: Coil Value to be written + +def WriteMultipleCoils(self, startingAddress, values) + +Write multiple coils to Server device (Function code 15) +startingAddress : First coil to be written +values: Coil Values [0..quantity-1] to be written + ''' + + def turnRelayOn(self, relay_id): + ''' + :param relay_id: id of relay to turn on + :return: None + ''' + self.mbclient.write_single_coil(relay_id-1, True) + + def turnRelayOff(self, relay_id): + ''' + :param relay_id: id of relay to turn off + :return: None + ''' + self.mbclient.write_single_coil(relay_id-11, False) + + def startSystemOp(self, mode, val): self.sc.setPortModes(mode) self.sc.setPortSetpoints(val) @@ -89,22 +125,6 @@ class Controller: 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 - if 0 <= fid <= 63: - try: - info_text = faultInfo[fid] - except IndexError: - info_text = "Fault Number: {} (Reserved)".format(fid) - self.view.text_fault_doc.SetValue(info_text) - - status_text = "Not Connected" - if self.sc: - fDict = self.sc.readFaultDetail(fid) - status_text = pprint.pformat(fDict) - self.view.text_fault_status.SetValue(status_text) - def OnTimer(self, event): # Read registers relay_status = self.mbclient.read_coils(0,10) @@ -226,9 +246,11 @@ class MyFrame(FaultFrame): pub.sendMessage("check_system_op_mode") def OnRelayOn(self, event): + pub.sendMessage("turn_relay_on", relay_id = event.GetId()) event.Skip() def OnRelayOff(self, event): + pub.sendMessage("turn_relay_off", relay_id = event.GetId()) event.Skip() def OnRelayPulse(self, event): diff --git a/FaultView.py b/FaultView.py index 7567e95..e73d2c2 100644 --- a/FaultView.py +++ b/FaultView.py @@ -1,6 +1,6 @@ # -*- coding: UTF-8 -*- # -# generated by wxGlade 0.9.6 on Fri Jul 24 15:09:44 2020 +# generated by wxGlade 0.9.6 on Wed Jul 29 12:53:09 2020 # import wx @@ -18,7 +18,7 @@ class FaultFrame(wx.Frame): # begin wxGlade: FaultFrame.__init__ kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) - self.SetSize((411, 480)) + self.SetSize((442, 480)) self.input_ip = wx.TextCtrl(self, wx.ID_ANY, _("192.168.1.2")) self.input_port = wx.TextCtrl(self, wx.ID_ANY, _("502")) self.input_uid = wx.TextCtrl(self, wx.ID_ANY, _("240")) @@ -27,46 +27,46 @@ class FaultFrame(wx.Frame): self.apply_button = wx.Button(self, wx.ID_ANY, _("Apply")) self.rreset_button = wx.Button(self, wx.ID_ANY, _("Remote PCS Reset")) self.button_1 = wx.ToggleButton(self, wx.ID_ANY, _("Start")) - self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_2 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_3 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_4 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_2 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_5 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_6 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_7 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_3 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_8 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_9 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_10 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_4 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_11 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_12 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_13 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_5 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_14 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_15 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_16 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_6 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_17 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_18 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_19 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_7 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_20 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_21 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_22 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_8 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_23 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_24 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_25 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_9 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_26 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_27 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_28 = wx.Button(self, wx.ID_ANY, _("PULSE")) - self.text_ctrl_10 = wx.TextCtrl(self, wx.ID_ANY, _("OFF"), style=wx.BORDER_NONE | wx.TE_CENTRE | wx.TE_READONLY) - self.button_29 = wx.Button(self, wx.ID_ANY, _("ON")) - self.button_30 = wx.Button(self, wx.ID_ANY, _("OFF")) - self.button_31 = wx.Button(self, wx.ID_ANY, _("PULSE")) + self.text_ctrl_1 = wx.TextCtrl(self, 1, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_2 = wx.Button(self, 1, _("ON")) + self.button_3 = wx.Button(self, 11, _("OFF")) + self.button_4 = wx.Button(self, 21, _("PULSE")) + self.text_ctrl_2 = wx.TextCtrl(self, 2, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_5 = wx.Button(self, 2, _("ON")) + self.button_6 = wx.Button(self, 12, _("OFF")) + self.button_7 = wx.Button(self, 22, _("PULSE")) + self.text_ctrl_3 = wx.TextCtrl(self, 3, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_8 = wx.Button(self, 3, _("ON")) + self.button_9 = wx.Button(self, 13, _("OFF")) + self.button_10 = wx.Button(self, 23, _("PULSE")) + self.text_ctrl_4 = wx.TextCtrl(self, 4, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_11 = wx.Button(self, 4, _("ON")) + self.button_12 = wx.Button(self, 14, _("OFF")) + self.button_13 = wx.Button(self, 24, _("PULSE")) + self.text_ctrl_5 = wx.TextCtrl(self, 5, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_14 = wx.Button(self, 5, _("ON")) + self.button_15 = wx.Button(self, 15, _("OFF")) + self.button_16 = wx.Button(self, 25, _("PULSE")) + self.text_ctrl_6 = wx.TextCtrl(self, 6, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_17 = wx.Button(self, 6, _("ON")) + self.button_18 = wx.Button(self, 16, _("OFF")) + self.button_19 = wx.Button(self, 26, _("PULSE")) + self.text_ctrl_7 = wx.TextCtrl(self, 7, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_20 = wx.Button(self, 7, _("ON")) + self.button_21 = wx.Button(self, 17, _("OFF")) + self.button_22 = wx.Button(self, 27, _("PULSE")) + self.text_ctrl_8 = wx.TextCtrl(self, 8, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_23 = wx.Button(self, 8, _("ON")) + self.button_24 = wx.Button(self, 18, _("OFF")) + self.button_25 = wx.Button(self, 28, _("PULSE")) + self.text_ctrl_9 = wx.TextCtrl(self, 9, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_26 = wx.Button(self, 9, _("ON")) + self.button_27 = wx.Button(self, 19, _("OFF")) + self.button_28 = wx.Button(self, 29, _("PULSE")) + self.text_ctrl_10 = wx.TextCtrl(self, 10, _("OFF"), style=wx.TE_CENTRE | wx.TE_READONLY) + self.button_29 = wx.Button(self, 10, _("ON")) + self.button_30 = wx.Button(self, 20, _("OFF")) + self.button_31 = wx.Button(self, 30, _("PULSE")) self.__set_properties() self.__do_layout() @@ -157,7 +157,6 @@ class FaultFrame(wx.Frame): sizer_4.Add(self.rreset_button, 0, 0, 0) sizer_4.Add(self.button_1, 0, 0, 0) sizer_7.Add(sizer_4, 0, wx.EXPAND, 0) - sizer_7.Add((20, 20), 0, wx.EXPAND, 0) label_5 = wx.StaticText(self, wx.ID_ANY, _("Relay 1")) sizer_2.Add(label_5, 0, 0, 0) sizer_2.Add((20, 20), 0, 0, 0) diff --git a/faultView.wxg b/faultView.wxg index 34f7e07..a9a9500 100644 --- a/faultView.wxg +++ b/faultView.wxg @@ -1,9 +1,9 @@ - + - 320, 480 + 442, 480 PCS Controller @@ -19,7 +19,7 @@ 0 wxEXPAND - 7 + 6 2 0 0 @@ -121,23 +121,6 @@ - - - 0 - - - OnCheckSysOpMode - - - - - - - 0 - - - - @@ -156,7 +139,7 @@ 0 - + @@ -170,10 +153,11 @@ 0 - - - 1 - + + 1 + #ff0000 + + OFF @@ -188,12 +172,10 @@ 0 - - 1 - OnRelayOn + 1 @@ -201,12 +183,10 @@ 0 - - 1 - OnRelayOff + 11 @@ -214,12 +194,10 @@ 0 - - 1 - OnRelayPulse + 21 @@ -235,7 +213,7 @@ 0 - + @@ -249,10 +227,11 @@ 0 - - - 1 - + + 2 + #ff0000 + + OFF @@ -267,12 +246,10 @@ 0 - - 2 - OnRelayOn + 2 @@ -280,12 +257,10 @@ 0 - - 2 - OnRelayOff + 12 @@ -293,12 +268,10 @@ 0 - - 2 - OnRelayPulse + 22 @@ -314,7 +287,7 @@ 0 - + @@ -328,10 +301,11 @@ 0 - - - 1 - + + 3 + #ff0000 + + OFF @@ -346,12 +320,10 @@ 0 - - 3 - OnRelayOn + 3 @@ -359,12 +331,10 @@ 0 - - 3 - OnRelayOff + 13 @@ -372,12 +342,10 @@ 0 - - 3 - OnRelayPulse + 23 @@ -393,7 +361,7 @@ 0 - + @@ -407,10 +375,11 @@ 0 - - - 1 - + + 4 + #ff0000 + + OFF @@ -425,12 +394,10 @@ 0 - - 4 - OnRelayOn + 4 @@ -438,12 +405,10 @@ 0 - - 4 - OnRelayOff + 14 @@ -451,12 +416,10 @@ 0 - - 4 - OnRelayPulse + 24 @@ -472,7 +435,7 @@ 0 - + @@ -486,10 +449,11 @@ 0 - - - 1 - + + 5 + #ff0000 + + OFF @@ -504,12 +468,10 @@ 0 - - 5 - OnRelayOn + 5 @@ -517,12 +479,10 @@ 0 - - 5 - OnRelayOff + 15 @@ -530,12 +490,10 @@ 0 - - 5 - OnRelayPulse + 25 @@ -551,7 +509,7 @@ 0 - + @@ -565,10 +523,11 @@ 0 - - - 1 - + + 6 + #ff0000 + + OFF @@ -583,12 +542,10 @@ 0 - - 6 - OnRelayOn + 6 @@ -596,12 +553,10 @@ 0 - - 6 - OnRelayOff + 16 @@ -609,12 +564,10 @@ 0 - - 6 - OnRelayPulse + 26 @@ -630,7 +583,7 @@ 0 - + @@ -644,10 +597,11 @@ 0 - - - 1 - + + 7 + #ff0000 + + OFF @@ -662,12 +616,10 @@ 0 - - 7 - OnRelayOn + 7 @@ -675,12 +627,10 @@ 0 - - 7 - OnRelayOff + 17 @@ -688,12 +638,10 @@ 0 - - 7 - OnRelayPulse + 27 @@ -709,7 +657,7 @@ 0 - + @@ -723,10 +671,11 @@ 0 - - - 1 - + + 8 + #ff0000 + + OFF @@ -741,12 +690,10 @@ 0 - - 8 - OnRelayOn + 8 @@ -754,12 +701,10 @@ 0 - - 8 - OnRelayOff + 18 @@ -767,12 +712,10 @@ 0 - - 8 - OnRelayPulse + 28 @@ -788,7 +731,7 @@ 0 - + @@ -802,10 +745,11 @@ 0 - - - 1 - + + 9 + #ff0000 + + OFF @@ -820,12 +764,10 @@ 0 - - 9 - OnRelayOn + 9 @@ -833,12 +775,10 @@ 0 - - 9 - OnRelayOff + 19 @@ -846,12 +786,10 @@ 0 - - 9 - OnRelayPulse + 29 @@ -867,7 +805,7 @@ 0 - + @@ -881,10 +819,11 @@ 0 - - - 10 - + + 10 + #ff0000 + + OFF @@ -899,12 +838,10 @@ 0 - - 10 - OnRelayOn + 10 @@ -912,12 +849,10 @@ 0 - - 10 - OnRelayOff + 20 @@ -925,12 +860,10 @@ 0 - - 10 - OnRelayPulse + 30