Write ASCII to serial, indentation fixes
This commit is contained in:
parent
5ed2c2e86b
commit
f52b1b2bfe
@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
import os
|
||||
from PyQt4 import QtCore, QtGui
|
||||
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
|
||||
from serial.tools import list_ports
|
||||
@ -117,14 +116,6 @@ class Ui_ConnectDialog(object):
|
||||
self.buttonBox.accepted.connect(connectDialog.accept)
|
||||
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):
|
||||
connectDialog.setWindowTitle(translate('ConnectDialog', 'Open Port'))
|
||||
self.portLabel.setText(translate('ConnectDialog', 'Port:'))
|
||||
@ -161,28 +152,6 @@ class Ui_ConnectDialog(object):
|
||||
self.readingCheckBox.setText(translate('ConnectDialog', 'Reading'))
|
||||
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):
|
||||
|
||||
def __init__(self):
|
||||
@ -209,3 +178,33 @@ class ConnectDialog(QtGui.QDialog, Ui_ConnectDialog):
|
||||
|
||||
def getHardwareHandshake(self):
|
||||
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 -*-
|
||||
import os
|
||||
import threading
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
@ -166,7 +167,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
output = ''
|
||||
|
||||
def onOpenActionTriggered(self):
|
||||
self.connectDialog.update_port_list()
|
||||
self.connectDialog.updatePortCombobox()
|
||||
if self.connectDialog.exec_() == QtGui.QDialog.Accepted:
|
||||
if not self.deviceClosed:
|
||||
self.deviceClosed = True
|
||||
@ -240,7 +241,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.sendComboBox.insertItem(0, output)
|
||||
self.sendComboBox.setCurrentIndex(0)
|
||||
self.sendComboBox.clearEditText()
|
||||
self.device.write(output + u'\r\n')
|
||||
self.device.write(output + '\r\n')
|
||||
|
||||
def onContentsSizeChanged(self, size):
|
||||
if self.followOutput:
|
||||
|
Loading…
Reference in New Issue
Block a user