def Write(self,event): client = ConnectDev() client.connect() if self.cb2.GetValue(): b1 = '1' else: b1 = '0' if self.cb1.GetValue(): b2 = '1' else: b2 = '0' if self.cb3.GetValue(): b3 = '1' else: b3 = '0' b = "00000%s%s%s" % (b3,b2,b1) c = SetAddressBit(self.sc.GetValue()) #print c+b d = int(c+b,2) rq=client.write_registers(1115,[d],unit=1) client.close() Saved(self)
def Read(self, event): client = ConnectDev() client.connect() rr = client.read_holding_registers(address=154,count=1,unit=1) result = rr.registers self.sc1.SetValue(result[0]) rr = client.read_holding_registers(address=1117,count=2,unit=1) result = rr.registers self.sc3.SetValue(result[0]) if ("00"+(bin(result[1]))[2:])[-1] == '1': self.cb1.SetValue(True) else: self.cb1.SetValue(False) if ("00"+(bin(result[1]))[2:])[-2] == '1': self.cb2.SetValue(True) else: self.cb2.SetValue(False) rr = client.read_holding_registers(address=1127,count=1,unit=1) result = rr.registers self.sc2.SetValue(result[0]) rr = client.read_holding_registers(address=1138,count=3,unit=1) result = rr.registers self.sc4.SetValue(result[0]) self.sc5.SetValue(result[1]) self.sc6.SetValue(result[2]) ### Ключ шифрования rr = client.read_holding_registers(address=1150,count=4,unit=1) result = rr.registers self.text_ctrl_1.SetValue(Reg2Key(result)) ### В пакетном режиме или нет rr = client.read_holding_registers(address=1159,count=1,unit=1) result = rr.registers if result[0] == 1: self.cb10.SetValue(True) else: self.cb10.SetValue(False) client.close()
def Read(self, event): client = ConnectDev() client.connect() ### IP адрес сервера rr = client.read_holding_registers(address=10,count=2,unit=1) result = rr.registers self.text_ctrl_3.SetValue(Registr2ip(result)) ### Порт сервера rr = client.read_holding_registers(address=15,count=1,unit=1) result = rr.registers port = hex(result[0]) port_string = "%s" % int(port,16) self.text_ctrl_4.SetValue(port_string) ### Шлюз rr = client.read_holding_registers(address=148,count=2,unit=1) result = rr.registers self.text_ctrl_5.SetValue(Registr2ip(result)) ### Использовать Etherner rr = client.read_holding_registers(address=146,count=1,unit=1) result = rr.registers if result[0] == 1: self.cb1.SetValue(True) else: self.cb1.SetValue(False) ### Использовать DHCP rr = client.read_holding_registers(address=147,count=1,unit=1) result = rr.registers if result[0] == 1: self.cb2.SetValue(True) else: self.cb2.SetValue(False) ### IP адрес устройства rr = client.read_holding_registers(address=152,count=2,unit=1) result = rr.registers self.text_ctrl_1.SetValue(Registr2ip(result)) ### Маска устройства rr = client.read_holding_registers(address=150,count=2,unit=1) result = rr.registers self.text_ctrl_2.SetValue(Registr2ip(result)) client.close()
def Write(self,event): result = self.text_ctrl_1.GetValue() client = ConnectDev() client.connect() rq=client.write_registers(158,Write16key(result),unit=1) client.close() Saved(self)
def ReadKey(self,event): client = ConnectDev() client.connect() rr = client.read_holding_registers(address=2064,count=4,unit=1) result = rr.registers client.close() result = "%s%s%s%s" % (Read2bytes(result[0]),Read2bytes(result[1]),Read2bytes(result[2]),Read2bytes(result[3])) self.text_ctrl_1.SetValue(StrRevers(result))
def Read(self, event): client = ConnectDev() client.connect() rr = client.read_holding_registers(address=154, count=1, unit=1) result = rr.registers self.sc1.SetValue(result[0]) rr = client.read_holding_registers(address=1117, count=2, unit=1) result = rr.registers self.sc3.SetValue(result[0]) if ("00" + (bin(result[1]))[2:])[-1] == '1': self.cb1.SetValue(True) else: self.cb1.SetValue(False) if ("00" + (bin(result[1]))[2:])[-2] == '1': self.cb2.SetValue(True) else: self.cb2.SetValue(False) rr = client.read_holding_registers(address=1127, count=1, unit=1) result = rr.registers self.sc2.SetValue(result[0]) rr = client.read_holding_registers(address=1138, count=3, unit=1) result = rr.registers self.sc4.SetValue(result[0]) self.sc5.SetValue(result[1]) self.sc6.SetValue(result[2]) ### Ключ шифрования rr = client.read_holding_registers(address=1150, count=4, unit=1) result = rr.registers self.text_ctrl_1.SetValue(Reg2Key(result)) ### В пакетном режиме или нет rr = client.read_holding_registers(address=1159, count=1, unit=1) result = rr.registers if result[0] == 1: self.cb10.SetValue(True) else: self.cb10.SetValue(False) client.close()
def Write(self,event): client = ConnectDev() client.connect() ### IP адрес сервера add_string = self.text_ctrl_3.GetValue() rq=client.write_registers(10,Ip2registr(add_string),unit=1) ### Порт сервера port_string = self.text_ctrl_4.GetValue() port = int(port_string) rq=client.write_registers(15,[port],unit=1) ### Шлюз add_string = self.text_ctrl_5.GetValue() rq=client.write_registers(148,Ip2registr(add_string),unit=1) ### Использовать Etherner if self.cb1.GetValue(): rq=client.write_registers(146,[1],unit=1) else: rq=client.write_registers(146,[0],unit=1) ### Использовать DHCP if self.cb2.GetValue(): rq=client.write_registers(147,[1],unit=1) else: rq=client.write_registers(147,[0],unit=1) ### IP адрес устройства add_string = self.text_ctrl_1.GetValue() rq=client.write_registers(152,Ip2registr(add_string),unit=1) ### Маска устройства add_string = self.text_ctrl_2.GetValue() rq=client.write_registers(150,Ip2registr(add_string),unit=1) client.close() Saved(self)
def Read(self,evt): client = ConnectDev() client.connect() ### Ключи пользователей ### Регистр 162 , читать 8 * 128 = 1024 data_key = [] adr = 512 reg = 162 step = 64 while adr > 0 : rr = client.read_holding_registers(address=reg,count=step,unit=1) result = rr.registers adr = adr - step reg = reg + step data_key.extend(result) ### Разделы пользователей data_part = [] adr = 128 reg = 930 step = 64 while adr > 0 : rr = client.read_holding_registers(address=reg,count=step,unit=1) result = rr.registers adr = adr - step reg = reg + step data_part.extend(result) client.close() for i in range(0,128): b8 = data_key[0:4] del data_key[0:4] result = "%s%s%s%s" % (Read2bytes(b8[0]),Read2bytes(b8[1]),Read2bytes(b8[2]),Read2bytes(b8[3])) self.keys[i].SetValue(result) part = data_part[0] del data_part[0] self.sections[i].SetValue(part)
def Read(self, event): client = ConnectDev() client.connect() rr = client.read_holding_registers(address=1115,count=1,unit=1) result = rr.registers a = (bin(result[0]))[2:] b = a[-8:] c = a[-16:-8] #print a,b,c ### Пожарная зона в разделе c1 = int(c,2) ## Пожарная зона вкл b1 = b[-1] ## Авт. сброс пожарной зоны b2 = b[-2] ## Двойная сработка пож. b3 = b[-3] self.sc.SetValue(GetAddressBit(c)) if b1 == '1': self.cb2.SetValue(True) else: self.cb2.SetValue(False) if b2 == '1': self.cb1.SetValue(True) else: self.cb1.SetValue(False) if b3 == '1': self.cb3.SetValue(True) else: self.cb3.SetValue(False) client.close()
def CheckConnect(self): try: client = ConnectDev() client.connect() rr = client.read_holding_registers(address=2064,count=4,unit=1) result = rr.registers client.close() dlg = wx.MessageDialog(self, u'Проверка связи прошла успешно!',u'Проверка %s' % GetDev(),wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() except: dlg = wx.MessageDialog(self, u'Проверка связи завершилась неудачей!',u'Проверка %s' % GetDev(),wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy()
def Write(self, event): client = ConnectDev() client.connect() rq = client.write_registers(154, [self.sc1.GetValue()], unit=1) rq = client.write_registers(1127, [self.sc2.GetValue()], unit=1) if self.cb1.GetValue(): b = "1" else: b = "0" if self.cb2.GetValue(): b = "1" + b else: b = "0" + b rq = client.write_registers( 1117, [self.sc3.GetValue(), int(b, 2)], unit=1) rq = client.write_registers( 1138, [self.sc4.GetValue(), self.sc5.GetValue(), self.sc6.GetValue()], unit=1) ### Ключ шифрования key = self.text_ctrl_1.GetValue() rq = client.write_registers(1150, Key2Reg(key), unit=1) ### В пакетном режиме или нет ### if self.cb10.GetValue(): rq = client.write_registers(1159, [1], unit=1) else: rq = client.write_registers(1159, [0], unit=1) client.close() Saved(self)
def Write(self, event): client = ConnectDev() client.connect() ### IP адрес сервера основной (4,5) ### IP адрес сервера GSM1(6,7) ### IP адрес сервера GSM2 (8,9) result = [] result.extend(Ip2registr(self.text_ctrl_11.GetValue())) result.extend(Ip2registr(self.text_ctrl_1.GetValue())) result.extend(Ip2registr(self.text_ctrl_2.GetValue())) rq = client.write_registers(4, result, unit=1) ### Порт сервера основной (12) ### Порт сервера GSM1 (13) ### Порт сервера GSM2 (14) result = [ int(self.text_ctrl_12.GetValue(), 10), int(self.text_ctrl_3.GetValue(), 10), int(self.text_ctrl_4.GetValue(), 10) ] rq = client.write_registers(12, result, unit=1) result = [] result.extend(Word2Reg(self.text_ctrl_5.GetValue(), 16)) result.extend(Word2Reg(self.text_ctrl_6.GetValue(), 16)) result.extend(Word2Reg(self.text_ctrl_7.GetValue(), 8)) result.extend(Word2Reg(self.text_ctrl_8.GetValue(), 8)) result.extend(Word2Reg(self.text_ctrl_9.GetValue(), 8)) result.extend(Word2Reg(self.text_ctrl_10.GetValue(), 8)) rq = client.write_registers(16, result, unit=1) client.close() Saved(self)
def Write(self,evt): data_key = [] data_part = [] for i in range(0,128): data_key.extend(Write16key(self.keys[i].GetValue())) data_part.append(int(self.sections[i].GetValue())) client = ConnectDev() client.connect() ### Ключи пользователей ### Регистр 162 , читать 8 * 128 = 1024 adr = 512 reg = 162 step = 64 while adr > 0 : result = data_key[:step] del data_key[:step] rq=client.write_registers(reg,result,unit=1) adr = adr - step reg = reg + step ### Разделы пользователей adr = 128 reg = 930 step = 64 while adr > 0 : result = data_part[:step] del data_part[:step] rq=client.write_registers(reg,result,unit=1) adr = adr - step reg = reg + step client.close() Saved(self)
def Write(self, event): client = ConnectDev() client.connect() rq=client.write_registers(154,[self.sc1.GetValue()],unit=1) rq=client.write_registers(1127,[self.sc2.GetValue()],unit=1) if self.cb1.GetValue(): b = "1" else: b = "0" if self.cb2.GetValue(): b = "1"+b else: b = "0"+b rq=client.write_registers(1117,[self.sc3.GetValue(),int(b,2)],unit=1) rq=client.write_registers(1138,[self.sc4.GetValue(),self.sc5.GetValue(),self.sc6.GetValue()],unit=1) ### Ключ шифрования key = self.text_ctrl_1.GetValue() rq=client.write_registers(1150,Key2Reg(key),unit=1) ### В пакетном режиме или нет ### if self.cb10.GetValue(): rq=client.write_registers(1159,[1],unit=1) else: rq=client.write_registers(1159,[0],unit=1) client.close() Saved(self)
def CheckConnect(self): try: client = ConnectDev() client.connect() rr = client.read_holding_registers(address=2064, count=4, unit=1) result = rr.registers client.close() dlg = wx.MessageDialog(self, u'Проверка связи прошла успешно!', u'Проверка %s' % GetDev(), wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() except: dlg = wx.MessageDialog(self, u'Проверка связи завершилась неудачей!', u'Проверка %s' % GetDev(), wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy()
def Read(self, event): client = ConnectDev() client.connect() ### IP адрес сервера основной (4,5) ### IP адрес сервера GSM1(6,7) ### IP адрес сервера GSM2 (8,9) rr = client.read_holding_registers(address=4, count=6, unit=1) result = rr.registers self.text_ctrl_11.SetValue(Registr2ip([result[0], result[1]])) self.text_ctrl_1.SetValue(Registr2ip([result[2], result[3]])) self.text_ctrl_2.SetValue(Registr2ip([result[4], result[5]])) ### Порт сервера основной (12) ### Порт сервера GSM1 (13) ### Порт сервера GSM2 (14) rr = client.read_holding_registers(address=12, count=3, unit=1) result = rr.registers self.text_ctrl_12.SetValue("%s" % result[0]) self.text_ctrl_3.SetValue("%s" % result[1]) self.text_ctrl_4.SetValue("%s" % result[2]) ### APN,User,Password rr = client.read_holding_registers(address=16, count=64, unit=1) result = rr.registers self.text_ctrl_5.SetValue(Reg2Word(result[0:16])) self.text_ctrl_6.SetValue(Reg2Word(result[16:32])) self.text_ctrl_7.SetValue(Reg2Word(result[32:40])) self.text_ctrl_8.SetValue(Reg2Word(result[40:48])) self.text_ctrl_9.SetValue(Reg2Word(result[48:56])) self.text_ctrl_10.SetValue(Reg2Word(result[56:64])) client.close()
def Read(self, event): client = ConnectDev() client.connect() rr = client.read_holding_registers(address=1066,count=14,unit=1) result = rr.registers list_keys = mode_enter.keys() list_values = mode_enter.values() self.ch_1.SetValue(list_keys[list_values.index(result[0])]) self.ch_2.SetValue(list_keys[list_values.index(result[1])]) self.ch_3.SetValue(list_keys[list_values.index(result[2])]) self.ch_4.SetValue(list_keys[list_values.index(result[3])]) self.ch_5.SetValue(list_keys[list_values.index(result[4])]) self.ch_6.SetValue(list_keys[list_values.index(result[5])]) self.ch_7.SetValue(list_keys[list_values.index(result[6])]) self.sc_1.SetValue(result[7]) self.sc_2.SetValue(result[8]) self.sc_3.SetValue(result[9]) self.sc_4.SetValue(result[10]) self.sc_5.SetValue(result[11]) self.sc_6.SetValue(result[12]) self.sc_7.SetValue(result[13]) rr = client.read_holding_registers(address=1128,count=7,unit=1) result = rr.registers for item in range(0,7): i = bin(result[item])[2:] a = "00000000"+i b = a[-8:] if b[7] == "1": eval("self.cb1_%s.SetValue(True)" % (item+1)) else: eval("self.cb1_%s.SetValue(False)" % (item+1)) if b[6] == "1": eval("self.cb2_%s.SetValue(True)" % (item+1)) else: eval("self.cb2_%s.SetValue(False)" % (item+1)) if b[5] == "1": eval("self.cb3_%s.SetValue(True)" % (item+1)) else: eval("self.cb3_%s.SetValue(False)" % (item+1)) if b[4] == "1": eval("self.cb4_%s.SetValue(True)" % (item+1)) else: eval("self.cb4_%s.SetValue(False)" % (item+1)) if b[3] == "1": eval("self.cb5_%s.SetValue(True)" % (item+1)) else: eval("self.cb5_%s.SetValue(False)" % (item+1)) if b[2] == "1": eval("self.cb6_%s.SetValue(True)" % (item+1)) else: eval("self.cb6_%s.SetValue(False)" % (item+1)) if b[1] == "1": eval("self.cb7_%s.SetValue(True)" % (item+1)) else: eval("self.cb7_%s.SetValue(False)" % (item+1)) if b[0] == "1": eval("self.cb8_%s.SetValue(True)" % (item+1)) else: eval("self.cb8_%s.SetValue(False)" % (item+1)) client.close()
def Write(self, event): client = ConnectDev() client.connect() ### Разделы row_int = [] for i in range(1, 9): item = "" for j in range(1, 17): if eval("self.cb%s_%s.GetValue()" % (i, j)): item = "1" + item else: item = "0" + item row_int.append(int(item, 2)) rq = client.write_registers(1080, row_int, unit=1) ### Зоны row_int = [] for i in range(1, 17): item = "" if eval("self.cb9_%s.GetValue()" % i): item = "1" + item else: item = "0" + item if eval("self.cb10_%s.GetValue()" % i): item = "1" + item else: item = "0" + item if eval("self.cb11_%s.GetValue()" % i): item = "1" + item else: item = "0" + item if eval("self.cb12_%s.GetValue()" % i): item = "10" + item else: item = "00" + item if eval("self.cb13_%s.GetValue()" % i): item = "1000" + item else: item = "0000" + item if eval("self.cb14_%s.GetValue()" % i): item = "10" + item else: item = "00" + item if eval("self.cb15_%s.GetValue()" % i): item = "1" + item else: item = "0" + item row_int.append(int(item, 2)) rq = client.write_registers(1098, row_int, unit=1) ### Входы, выходы row_int = [0, 0, 0, 0, 0, 0, 0, 0] for i in range(0, 8): enter_value = eval("self.sc%s_1.GetValue()" % (i + 1)) exit_value = eval("self.sc%s_2.GetValue()" % (i + 1)) row_int[i] = int((hex(enter_value))[2:].rjust(2, "0") + ((hex(exit_value))[2:].rjust(2, "0")), 16) #print row_int rq = client.write_registers(1089, row_int, unit=1) ### ID разделов ids = [] for item in range(1, 9): v = eval("self.sc%s_0.GetValue()" % item) ids.append(v) rq = client.write_registers(1142, ids, unit=1) client.close() Saved(self)
def Write(self, event): client = ConnectDev() client.connect() r = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] r[0] = mode_enter[self.ch_1.GetValue()] r[1] = mode_enter[self.ch_2.GetValue()] r[2] = mode_enter[self.ch_3.GetValue()] r[3] = mode_enter[self.ch_4.GetValue()] r[4] = mode_enter[self.ch_5.GetValue()] r[5] = mode_enter[self.ch_6.GetValue()] r[6] = mode_enter[self.ch_7.GetValue()] r[7] = self.sc_1.GetValue() r[8] = self.sc_2.GetValue() r[9] = self.sc_3.GetValue() r[10] = self.sc_4.GetValue() r[11] = self.sc_5.GetValue() r[12] = self.sc_6.GetValue() r[13] = self.sc_7.GetValue() rq=client.write_registers(1066,r,unit=1) bb = [0,0,0,0,0,0,0] cc = ['','','','','','',''] for item in range(0,7): a = eval("self.cb1_%s.GetValue()" % (item+1)) b = eval("self.cb2_%s.GetValue()" % (item+1)) c = eval("self.cb3_%s.GetValue()" % (item+1)) d = eval("self.cb4_%s.GetValue()" % (item+1)) e = eval("self.cb5_%s.GetValue()" % (item+1)) f = eval("self.cb6_%s.GetValue()" % (item+1)) g = eval("self.cb7_%s.GetValue()" % (item+1)) h = eval("self.cb8_%s.GetValue()" % (item+1)) if a: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if b: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if c: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if d: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if e: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if f: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if g: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] if h: cc[item] = "1"+cc[item] else: cc[item] = "0"+cc[item] for i in range(0,7): bb[i] = int(cc[i],2) rq=client.write_registers(1128,bb,unit=1) client.close()
def Read(self, event): client = ConnectDev() client.connect() ### Разделы rr = client.read_holding_registers(address=1080, count=8, unit=1) result = rr.registers row_bit = [] for row in result: row_bit.append((("0" * 16) + (bin(row)[2:]))[-16:]) for i in range(1, 9): for j in range(1, 17): if (row_bit[(i - 1)])[-(j)] == "1": eval("self.cb%s_%s.SetValue(True)" % (i, j)) else: eval("self.cb%s_%s.SetValue(False)" % (i, j)) ### Зоны rr = client.read_holding_registers(address=1098, count=16, unit=1) result = rr.registers row_bit = [] for row in result: row_bit.append((bin(row)[2:]).rjust(16, "0")) for i in range(1, 17): if (row_bit[(i - 1)])[-1] == "1": eval("self.cb9_%s.SetValue(True)" % i) else: eval("self.cb9_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-2] == "1": eval("self.cb10_%s.SetValue(True)" % i) else: eval("self.cb10_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-3] == "1": eval("self.cb11_%s.SetValue(True)" % i) else: eval("self.cb11_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-5] == "1": eval("self.cb12_%s.SetValue(True)" % i) else: eval("self.cb12_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-9] == "1": eval("self.cb13_%s.SetValue(True)" % i) else: eval("self.cb13_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-11] == "1": eval("self.cb14_%s.SetValue(True)" % i) else: eval("self.cb14_%s.SetValue(False)" % i) if (row_bit[(i - 1)])[-12] == "1": eval("self.cb15_%s.SetValue(True)" % i) else: eval("self.cb15_%s.SetValue(False)" % i) ### Входы, выходы rr = client.read_holding_registers(address=1089, count=8, unit=1) result = rr.registers #print result for i in range(0, 8): tworeg = (hex(result[i])[2:]).rjust(4, "0") enter_value = int(tworeg[0:2], 16) exit_value = int(tworeg[2:4], 16) #print tworeg,enter_value,enter_value eval("self.sc%s_1.SetValue(enter_value)" % (i + 1)) eval("self.sc%s_2.SetValue(exit_value)" % (i + 1)) ### ID разделов rr = client.read_holding_registers(address=1142, count=8, unit=1) result = rr.registers t = 0 for item in result: t = t + 1 eval("self.sc%s_0.SetValue(%s)" % (t, item)) client.close()