def conn_button_onclick(self, event): #self.log_text.AppendText('Conn %s %s '% (self.port_combo.GetValue(), self.m_comboBox2.GetValue())) if not self.__serialPort.status: connected = True baudrate = self.m_comboBox2.GetValue() iprCmd = None if int(baudrate) > 115200: iprCmd = ATcommand(atcmds.IPR_CMD_ID, True, [baudrate]) baudrate = "115200" if self.__serialPort.start(self.port_combo.GetValue(), baudrate): self.setConnectionStatus(True) cmd = ATcommand(atcmds.AT_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) cmd = ATcommand(atcmds.ATE0_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) if iprCmd is not None: self.__serialPort.sendCommand(iprCmd) else: connected = False if not connected: self.log_text.AppendText( 'Error: Could not connect to serial port!') else: self.conn_button.SetLabelText('Disconnect') else: self.__serialPort.writeDirect("AT+IPR=0\r\n") self.__serialPort.stop() self.conn_button.SetLabelText('Connect')
def status_buttonOnButtonClick(self, event): if self.__serialPort.status: cmd = ATcommand(atcmds.CPIN_CMD_ID, False, None) self.__serialPort.sendCommand(cmd) cmd = ATcommand(atcmds.CSQ_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) cmd = ATcommand(atcmds.CGATT_CMD_ID, False, None) self.__serialPort.sendCommand(cmd) else: self.log_text.AppendText("\nSerial connection closed")
def loadAllScripts(path): filenames = [] for file in os.listdir(path): if file.endswith(".xml"): filenames.append(file.replace('.xml', '')) if len(filenames): for file in filenames: try: script = [] tree = ET.parse(path + file + '.xml').getroot() for elem in tree: #commandsList if elem.tag == "cmd": if elem.attrib['id'] in commandsList: cmd = ATcommand(elem.attrib['id'], (elem.attrib['setMode'] == '1'), elem.attrib['params'].split('|')) script.append(cmd) #print "CMD %s, %u, %s" % (cmd.cmd, cmd.setOperation, elem.attrib['params']) else: print "Invalid AT command read %s" % elem.attrib[ 'id'] # print "param %s = %s" % (elem.attrib['name'], elem.text) scriptsList[file] = script except ET.ParseError: print "Error parsing XML" return filenames
def close_remote_conn_buttonOnButtonClick(self, event): self.__socketRedirection = False if self.__serialPort.status: self.__serialPort.writeDirect("+++") self.__serialPort.rawMode = False time.sleep(2) cmd = ATcommand(atcmds.CIPSHUT_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) if self.__localSocket.status: self.__localSocket.stop()
def connect_remote_buttonOnButtonClick(self, event): if self.__serialPort.status: if not self.__serialPort.rawMode: params = [ self.conntype_combo.GetValue(), self.remoteaddress_text.GetValue(), self.remoteport_text.GetValue() ] cmd = ATcommand(atcmds.CIPSTART_CMD_ID, True, params) self.__serialPort.sendCommand(cmd) else: logger.info("Connection already open")
def _answerIPRHandler(self, answer): if answer.ok: if self.__serialPort.reconnect(self.port_combo.GetValue(), self.m_comboBox2.GetValue()): connected = True cmd = ATcommand(atcmds.AT_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) else: connected = False else: connected = False if not connected: wx.CallAfter(pub.sendMessage, "AppendLogText", text='Error: Could not connect to serial port!') self.setConnectionStatus(False) else: self.setConnectionStatus(True)
def rxAnswerReconectCallback(self, answer): if answer.cmdId == atcmds.IPR_CMD_ID: connected = True if answer.ok: self.__serialPort.receivedAnswer = self.rxAnswerCallback self.__serialPort.stop() if self.__serialPort.start(self.port_combo.GetValue(), self.m_comboBox2.GetValue()): cmd = ATcommand(atcmds.AT_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) else: connected = False else: connected = False if not connected: wx.CallAfter(pub.sendMessage, "AppendLogText", text='Error: Could not connect to serial port!') self.setConnectionStatus(False) else: self.setConnectionStatus(True) else: self.rxAnswerCallback(answer)
def info_buttonOnButtonClick(self, event): if self.__serialPort.status: cmd = ATcommand(atcmds.ATI_CMD_ID, True, None) self.__serialPort.sendCommand(cmd) else: self.log_text.AppendText("\nSerial connection closed")