Write ASCII to serial, indentation fixes
This commit is contained in:
parent
5ed2c2e86b
commit
f52b1b2bfe
@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
|
||||||
import os
|
import os
|
||||||
|
from PyQt4 import QtCore, QtGui
|
||||||
from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
|
from serial import Serial, FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS, PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK,\
|
||||||
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
|
PARITY_SPACE, STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO, SerialException
|
||||||
from serial.tools import list_ports
|
from serial.tools import list_ports
|
||||||
@ -117,14 +116,6 @@ class Ui_ConnectDialog(object):
|
|||||||
self.buttonBox.accepted.connect(connectDialog.accept)
|
self.buttonBox.accepted.connect(connectDialog.accept)
|
||||||
self.buttonBox.rejected.connect(connectDialog.reject)
|
self.buttonBox.rejected.connect(connectDialog.reject)
|
||||||
|
|
||||||
def update_port_list(self):
|
|
||||||
self.portEdit.clear()
|
|
||||||
ports = []
|
|
||||||
for port in self.serial_ports():
|
|
||||||
ports.append(port)
|
|
||||||
ports.sort()
|
|
||||||
self.portEdit.addItems(ports)
|
|
||||||
|
|
||||||
def retranslateUi(self, connectDialog):
|
def retranslateUi(self, connectDialog):
|
||||||
connectDialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
|
connectDialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
|
||||||
self.portLabel.setText(translate('ConnectDialog', 'Port:'))
|
self.portLabel.setText(translate('ConnectDialog', 'Port:'))
|
||||||
@ -161,28 +152,6 @@ class Ui_ConnectDialog(object):
|
|||||||
self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
|
self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
|
||||||
self.writingCheckBox.setText(translate('ConnectDialog', 'Writing'))
|
self.writingCheckBox.setText(translate('ConnectDialog', 'Writing'))
|
||||||
|
|
||||||
def serial_ports(self):
|
|
||||||
"""
|
|
||||||
Returns a generator for all available serial ports
|
|
||||||
"""
|
|
||||||
if os.name == 'nt':
|
|
||||||
# windows
|
|
||||||
for i in range(256):
|
|
||||||
try:
|
|
||||||
s = Serial(i)
|
|
||||||
s.close()
|
|
||||||
yield 'COM' + str(i + 1)
|
|
||||||
except SerialException:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
# unix
|
|
||||||
try:
|
|
||||||
for port in list_ports.comports():
|
|
||||||
yield port[0]
|
|
||||||
except NameError:
|
|
||||||
# pyserial 2.6 cannot handle serial usb ports very well, in that case just do not provide a list
|
|
||||||
pass
|
|
||||||
|
|
||||||
class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
|
class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -209,3 +178,33 @@ class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
|
|||||||
|
|
||||||
def getHardwareHandshake(self):
|
def getHardwareHandshake(self):
|
||||||
return self.hardwareCheckBox.isChecked()
|
return self.hardwareCheckBox.isChecked()
|
||||||
|
|
||||||
|
def updatePortCombobox(self):
|
||||||
|
self.portEdit.clear()
|
||||||
|
ports = []
|
||||||
|
for port in self._getSerialPorts():
|
||||||
|
ports.append(port)
|
||||||
|
ports.sort()
|
||||||
|
self.portEdit.addItems(ports)
|
||||||
|
|
||||||
|
def _getSerialPorts(self):
|
||||||
|
"""
|
||||||
|
Returns a generator for all available serial ports
|
||||||
|
"""
|
||||||
|
if os.name == 'nt':
|
||||||
|
# windows
|
||||||
|
for i in range(256):
|
||||||
|
try:
|
||||||
|
s = Serial(i)
|
||||||
|
s.close()
|
||||||
|
yield 'COM' + str(i + 1)
|
||||||
|
except SerialException:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# unix
|
||||||
|
try:
|
||||||
|
for port in list_ports.comports():
|
||||||
|
yield port[0]
|
||||||
|
except NameError:
|
||||||
|
# pyserial 2.6 cannot handle serial usb ports very well, in that case just do not provide a list
|
||||||
|
pass
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
@ -166,7 +167,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
output = ''
|
output = ''
|
||||||
|
|
||||||
def onOpenActionTriggered(self):
|
def onOpenActionTriggered(self):
|
||||||
self.connectDialog.update_port_list()
|
self.connectDialog.updatePortCombobox()
|
||||||
if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
|
if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
|
||||||
if not self.deviceClosed:
|
if not self.deviceClosed:
|
||||||
self.deviceClosed = True
|
self.deviceClosed = True
|
||||||
@ -240,7 +241,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
self.sendComboBox.insertItem(0, output)
|
self.sendComboBox.insertItem(0, output)
|
||||||
self.sendComboBox.setCurrentIndex(0)
|
self.sendComboBox.setCurrentIndex(0)
|
||||||
self.sendComboBox.clearEditText()
|
self.sendComboBox.clearEditText()
|
||||||
self.device.write(output + u'\r\n')
|
self.device.write(output + '\r\n')
|
||||||
|
|
||||||
def onContentsSizeChanged(self, size):
|
def onContentsSizeChanged(self, size):
|
||||||
if self.followOutput:
|
if self.followOutput:
|
||||||
@ -292,13 +293,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
style = u'%sbackground-color: %s; ' % (style, highlight.background)
|
style = u'%sbackground-color: %s; ' % (style, highlight.background)
|
||||||
break
|
break
|
||||||
if style:
|
if style:
|
||||||
try:
|
try:
|
||||||
output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
|
output = u'<div style="%s">%s</div>' % (style, unicode(output, u'utf-8'))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
output = u'<div style="%s">%s</div>' % (style, output)
|
output = u'<div style="%s">%s</div>' % (style, output)
|
||||||
else:
|
else:
|
||||||
output = u'<div>%s</div>' % output
|
output = u'<div>%s</div>' % output
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def saveHighlights(self, highlights):
|
def saveHighlights(self, highlights):
|
||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
|
Loading…
Reference in New Issue
Block a user