-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortDialog.py
73 lines (64 loc) · 3.29 KB
/
PortDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'PortDialog.ui'
#
# Created: Wed Jul 28 12:45:43 2010
# by: PyQt4 UI code generator 4.5.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
from serial import *
from glob import glob
class Ui_PortDialog(object):
def setupUi(self, PortDialog):
PortDialog.setObjectName('PortDialog')
PortDialog.resize(388, 110)
self.verticalLayout = QtGui.QVBoxLayout(PortDialog)
self.verticalLayout.setObjectName('verticalLayout')
self.PortsBox = QtGui.QHBoxLayout()
self.PortsBox.setObjectName('PortsBox')
self.PortsListBox = QtGui.QComboBox(PortDialog)
self.PortsListBox.setEditable(True)
self.PortsListBox.setObjectName('PortsListBox')
self.PortsBox.addWidget(self.PortsListBox)
self.PortScanBtn = QtGui.QPushButton(PortDialog)
self.PortScanBtn.setMaximumSize(QtCore.QSize(100, 16777215))
self.PortScanBtn.setObjectName('PortScanBtn')
self.PortsBox.addWidget(self.PortScanBtn)
self.verticalLayout.addLayout(self.PortsBox)
self.ButtonBox = QtGui.QHBoxLayout()
self.ButtonBox.setObjectName('ButtonBox')
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.ButtonBox.addItem(spacerItem)
self.StartBtn = QtGui.QPushButton(PortDialog)
self.StartBtn.setObjectName('StartBtn')
self.ButtonBox.addWidget(self.StartBtn)
self.CancelBtn = QtGui.QPushButton(PortDialog)
self.CancelBtn.setObjectName('CancelBtn')
self.ButtonBox.addWidget(self.CancelBtn)
self.verticalLayout.addLayout(self.ButtonBox)
self.retranslateUi(PortDialog)
QtCore.QObject.connect(self.CancelBtn, QtCore.SIGNAL('clicked()'), PortDialog.close)
QtCore.QObject.connect(self.PortScanBtn, QtCore.SIGNAL('clicked()'), self.scanPorts)
QtCore.QMetaObject.connectSlotsByName(PortDialog)
def retranslateUi(self, PortDialog):
PortDialog.setWindowTitle(QtGui.QApplication.translate('PortDialog', 'Zeo Raw Data Viewer', None, QtGui.QApplication.UnicodeUTF8))
self.PortScanBtn.setText(QtGui.QApplication.translate('PortDialog', 'Scan Ports', None, QtGui.QApplication.UnicodeUTF8))
self.StartBtn.setText(QtGui.QApplication.translate('PortDialog', 'Start', None, QtGui.QApplication.UnicodeUTF8))
self.CancelBtn.setText(QtGui.QApplication.translate('PortDialog', 'Cancel', None, QtGui.QApplication.UnicodeUTF8))
PortDialog.setWindowIcon(QtGui.QIcon('zeo.png'))
def scanPorts(self):
self.PortsListBox.clear()
# Helps find USB>Serial converters on linux
for p in glob('/dev/tty.usbserial*'):
self.PortsListBox.addItem(p)
#Linux and Windows
for i in range(256):
try:
ser = Serial(i)
if ser.isOpen():
#Check that the port is actually valid
#Otherwise invalid /dev/ttyS* ports may be added
self.PortsListBox.addItem(ser.portstr)
ser.close()
except SerialException:
pass