Esempio n. 1
0
def main(args):
	
	def quit():
		se.stop()
		s.close()
	
	def portChanged(portName):
		print('Port changed: ', portName)
		
	def tryConnect():
		if not s.isOpen():
			s.port = ports_cb.currentText()
			s.open()
			connect.setText('Connected')

	def readChipID():
		s.write("print(node.chipid())\n")

	def showip():
		s.write('print(wifi.sta.getip())\n')

	def setwifi():
		s.write('wifi.setmode(wifi.STATION)\n')
		s.write('wifi.sta.config("%s", "%s")\n' % (str(ssidtext.text()), str(pwdtext.text())))
		s.write('wifi.sta.connect()\n')
		#print 'status\n', se.readAll().decode("utf-8")

	def sendStr():
		t = str(sendtext.toPlainText()+'\n')
		print "Text=",t
		if len(t)>0:
			s.write(t)
	def write():
		#print 'NEW DATA?',se.readAll().decode("utf-8")
		textedit.setText(textedit.toPlainText() + se.readAll().decode("utf-8"))
		return
	
	a = QtGui.QApplication(args)
	
	matchedPorts = list_serial_ports()
	
	ports_cb = QtGui.QComboBox()
	ports_cb.currentIndexChanged[str].connect(portChanged)
	
	for port in reversed(matchedPorts):
		ports_cb.addItem(port)
	
	connect = QPushButton("Connect")
	connect.clicked.connect(tryConnect)

	uart = QHBoxLayout()
	uart.addWidget(ports_cb)
	uart.addWidget(connect)

	#chipid = QPushButton("Read chipID")
	#chipid.clicked.connect(readChipID)
	wifi = QHBoxLayout()
	wifi1 = QVBoxLayout()
	ssidlabel = QLabel('SSID:')
	ssidlabel.setAlignment(Qt.AlignLeft)
	ssidtext = QLineEdit()
	ssidtext.setMaxLength(32)
	ssidtext.setMaximumWidth(80)
	ssidtext.setAlignment(Qt.AlignLeft)
	wifi1.addWidget(ssidlabel)
	wifi1.addWidget(ssidtext)
	wifi2 = QVBoxLayout()
	pwdlabel = QLabel('Password:'******'Show IP')
	ip.clicked.connect(showip)
	wifi3.addWidget(ip)
	wifi3.addWidget(setupwifi)
	wifi.addLayout(wifi1)
	#wifi.addStretch(1)
	wifi.addLayout(wifi2)
	wifi.addLayout(wifi3)

	comm = QVBoxLayout()
	textedit = QTextEdit()
	sendlabel = QLabel('Send Text')
	sendtext = QTextEdit()
	sendtext.setMaximumHeight(sendlabel.sizeHint().height() * 4)
	send = QPushButton("Send")
	send.clicked.connect(sendStr)
	comm.addWidget(textedit)
	comm.addWidget(sendlabel)
	comm.addWidget(sendtext)
	comm.addWidget(send)

	full = QVBoxLayout()
	full.addLayout(uart)
	full.addLayout(wifi)
	full.addLayout(comm)

	s = serial.Serial()
	
	se = SerialEvents(s)
	se.readyRead.connect(write)
	se.start()
	
	window =  QWidget()
	layout =  QVBoxLayout()
	
	window.setWindowTitle('Serial Terminal')
	window.setLayout(full)
	window.show()
	
	r = a.exec_()
	quit()
	return r
Esempio n. 2
0
def main(args):
	
	def quit():
		se.stop()
		s.close()
	
	def portChanged(portName):
		print('Port changed: ', portName)
		
	def tryConnect():
		if not s.isOpen():
			s.port = ports_cb.currentText()
			s.open()
			connect.setText('Connected')
	
	def sendStr():
		s.write(bytes('ABCDEF', 'UTF-8'))
		
	def write():
		processedText = pm.process(textedit.toPlainText(), se.readAll().decode("utf-8"))
		
		textedit.setText(processedText)
	
	
	a = QtGui.QApplication(args)
	
	matchedPorts = PortsListener.getPorts()
	
	ports_cb = QtGui.QComboBox()
	ports_cb.currentIndexChanged[str].connect(portChanged)
	
	for port in matchedPorts:
		ports_cb.addItem(port)	# TODO: add QVariant with port data
	
	connect = QPushButton("Connect")
	connect.clicked.connect(tryConnect)
	
	send = QPushButton("Send")
	send.clicked.connect(sendStr)
	
	textedit = QTextEdit()
	
	
	pm = PluginManager()
	
	plugins_cb = QComboBox()
	plugins_cb.addItems(list(pm.plugins.keys()))
	
	
	s = serial.Serial()
	
	se = SerialEvents(s)
	se.readyRead.connect(write)
	se.start()
	
	# try:
	# 	s = serial.Serial('/dev/cu.usbserial-A6008cB6')
	# except (FileNotFoundError, serial.SerialException):
	# 	print("Error")
	
	
	window =  QWidget()
	layout =  QVBoxLayout()
	
	layout.addWidget(ports_cb)
	layout.addWidget(connect)
	layout.addWidget(send)
	layout.addWidget(textedit)
	layout.addWidget(plugins_cb)
	
	window.setLayout(layout)
	window.show()
	
	
	r = a.exec_()
	quit()
	return r
Esempio n. 3
0
def main(args):
	
	def quit():
		se.stop()
		s.close()
	
	def portChanged(portName):
		print('Port changed: ', portName)
		
	def tryConnect():
		if not s.isOpen():
			s.port = ports_cb.currentText()
			s.open()
			connect.setText('Connected')

	def readChipID():
		s.write("print(node.chipid())\n")

	def showip():
		s.write('print(wifi.sta.getip())\n')

	def list_accesspoints():
		""" This function will print out the Access-Point list """
		listap = ['wifi.setmode(wifi.STATION)\n',
                  "function listap(t)\n",
                  "  for k,v in pairs(t) do\n",
                  "    print(k..\" : \"..v)\n",
                  "  end\n",
                  "end\n",
                  "print('***Wifi Networks:***')\n",
                  "wifi.sta.getap(listap)\n"]
		for c in listap:
			s.write(c)
			sleep(.5)

	def setwifi():
		s.write('wifi.setmode(wifi.STATION)\n')
		s.write('wifi.sta.config("%s", "%s")\n' % (str(ssidtext.text()), str(pwdtext.text())))
		s.write('wifi.sta.connect()\n')
		#print 'status\n', se.readAll().decode("utf-8")

	def sendStr():
		t = str(sendtext.toPlainText()+'\n')
		print "Text=",t
		if len(t)>0:
			s.write(t)
	def write():
		#print 'NEW DATA?',se.readAll().decode("utf-8")
		textedit.setText(textedit.toPlainText() + se.readAll().decode("utf-8"))
		return

	def restart():
		textedit.setText("")
		s.write('node.restart()\n')
	# A function that tries to list serial ports on most common platforms
	def list_serial_ports():
		system_name = platform.system()
		if system_name == "Windows":
			# Scan for available ports.
			available = []
			for i in range(256):
				try:
					s = serial.Serial(i)
					available.append("COM%d" % (i+1))
					s.close()
				except serial.SerialException:
					pass
			return available
		elif system_name == "Darwin":
			# Mac
			return glob.glob('/dev/tty*') + glob.glob('/dev/cu*')
		else:
			# Assume Linux or something else
			return glob.glob('/dev/ttyS*') + glob.glob('/dev/ttyUSB*')

	a = QtGui.QApplication(args)
	
	matchedPorts = list_serial_ports()
	
	ports_cb = QtGui.QComboBox()
	ports_cb.currentIndexChanged[str].connect(portChanged)
	
	for port in reversed(matchedPorts):
		ports_cb.addItem(port)
	
	connect = QPushButton("Connect")
	connect.clicked.connect(tryConnect)

	uart = QHBoxLayout()
	uart.addWidget(ports_cb)
	uart.addWidget(connect)

	#chipid = QPushButton("Read chipID")
	#chipid.clicked.connect(readChipID)
	wifi = QHBoxLayout()
	wifi1 = QVBoxLayout()
	ssidlabel = QLabel('SSID:')
	ssidlabel.setAlignment(Qt.AlignLeft)
	ssidtext = QLineEdit()
	ssidtext.setMaxLength(32)
	ssidtext.setMaximumWidth(80)
	ssidtext.setAlignment(Qt.AlignLeft)
	wifi1.addWidget(ssidlabel)
	wifi1.addWidget(ssidtext)
	wifi2 = QVBoxLayout()
	pwdlabel = QLabel('Password:'******'Show IP')
	ip.clicked.connect(showip)
	wifi3.addWidget(ip)
	wifi3.addWidget(setupwifi)
	wifi.addLayout(wifi1)
	#wifi.addStretch(1)
	wifi.addLayout(wifi2)
	wifi.addLayout(wifi3)

	comm = QVBoxLayout()
	textedit = QTextEdit()
	sendlabel = QLabel('Send Text')
	sendtext = QTextEdit()
	sendtext.setMaximumHeight(sendlabel.sizeHint().height() * 4)
	send = QPushButton("Send")
	send.clicked.connect(sendStr)

	reset = QPushButton("Restart")
	reset.clicked.connect(restart)

	listAP = QPushButton("List AP")
	listAP.clicked.connect(list_accesspoints)

	comm.addWidget(textedit)
	comm.addWidget(sendlabel)
	comm.addWidget(sendtext)
	comm.addWidget(send)

	comm.addWidget(reset)
	comm.addWidget(listAP)

	full = QVBoxLayout()
	full.addLayout(uart)
	full.addLayout(wifi)
	full.addLayout(comm)

	s = serial.Serial()
	
	se = SerialEvents(s)
	se.readyRead.connect(write)
	se.start()
	
	window =  QWidget()
	layout =  QVBoxLayout()
	
	window.setLayout(full)
	window.setWindowTitle('Terminal for ESP8266')
	window.show()
	
	r = a.exec_()
	quit()
	return r