#-*- coding: utf-8 -*-
from time import ctime
from PyQt4 import QtCore, QtGui, uic
from datetime import date, time, datetime, timedelta
import serial
import Util
import threading
import sys
from mainwindow import Ui_MainWindow as SerCom_UIForm
import comm_configtool
from SerialCom import SerialCom
ff = False
class SerCom_UiHandler(QtGui.QMainWindow,SerCom_UIForm):
def __init__(self, parent=None):
super(SerCom_UiHandler,self).__init__(parent)
self.setupUi(self)
self.comseting=comm_configtool.ConfigCommForm()
self.flags = {"__isopen__": False, "__datatype__": "ascii"}
self.creatAction()
self.creatMenu()
self.__setupSignal()
self.comseting.connect(self.comseting.pushButton,QtCore.SIGNAL("clicked()"),self.slotseting)
def creatAction(self):
self.clearAction = QtGui.QAction(QtGui.QIcon('claer.png'), '&clear', self)
self.clearAction.setShortcut('Ctrl+Q')
self.clearAction.setStatusTip('claer textEdit')
self.connect(self.clearAction,QtCore.SIGNAL("triggered()"),self.slotClearText)
self.setCommAction = QtGui.QAction(QtGui.QIcon('setComm.png'), '&setComm', self)
self.setCommAction.setShortcut('Ctrl+S')
self.setCommAction.setStatusTip('set Comm port')
self.connect(self.setCommAction,QtCore.SIGNAL("triggered()"),self.slotOpenConfForm)
def creatMenu(self):
fileMenu = self.menubar.addMenu('&File')
fileMenu.addAction(self.clearAction)
setcommMenu = self.menubar.addMenu('&setcomm')
setcommMenu.addAction(self.setCommAction)
def __setupSignal(self):
self.pushButton_RS.clicked.connect(self.__readCPStatus)
self.pushButton_SD.clicked.connect(self.__sendBufData)
self.pushButton_SC.clicked.connect(self.sendBufcmd)
self.radioButton_Pon.clicked.connect(self.__powerContrlcmd)
self.radioButton_Poff.clicked.connect(self.__powerContrlcmd)
self.pushButton_TTS.clicked.connect(self.__TemperatureTestStart)
self.pushButton_TTE.clicked.connect(self.__TemperatureTestStop)
self.pushButton_Clear.clicked.connect(self.slotClearText)
def serialPara(self):
pass
def __onOpenPort(self):
if self.flags["__isopen__"]:
return self.__closePort()
ret, msg = self.__openPort()
if not ret:
QtGui.QMessageBox.critical(self, "Error", msg)
self.confFormOpen()
else:
self.flags["__isopen__"] = True
self.serial.start()
def __openPort(self, settings=None):
if not settings:
settings = { "port": None, "baund": 9600, "bytesize": 8,
"parity":'N', "stopbits": 1, "timeout": 1}
settings["port"] =self.comseting.comboBox_2.currentText().toUtf8().data()
settings["baund"] = self.comseting.comboBox.currentText().toUtf8().data()
settings["bytesize"] = self.comseting.comboBox_3.currentText().toUtf8().data()
#settings["parity"] = self.comseting.comboBox_4.currentText().toUtf8().data()
#settings["parity"] = 'N'
settings["timeout"] = 1
ret, msg = Util.formatPortSettins(settings)
if not ret:
return False, msg
if not settings["port"]:
return False, u"错误的串口号"
self.serial = SerialCom()
self.connect(self.serial.qtobj, QtCore.SIGNAL("NewData"), self.onRecvData)
ret, msg = self.serial.open(settings)
return ret, msg
def __closePort(self):
self.serial.terminate()
self.textBrowser_DR.append(str("serial com port closed"))
self.flags["__isopen__"] = False
def slotClearText(self):
self.textBrowser_DR.clear()
def slotOpenConfForm(self):
self.comseting.exec_()
def slotseting(self):
if self.comseting.pushButton.text() == "Open":
self.confFormClose()
self.__onOpenPort()
elif self.comseting.pushButton.text() == "close":
self.confFormOpen()
self.__closePort()
def confFormClose(self):
self.comseting.comboBox_2.setDisabled(True)
self.comseting.comboBox.setDisabled(True)
self.comseting.comboBox_3.setDisabled(True)
self.comseting.comboBox_4.setDisabled(True)
self.comseting.comboBox_5.setDisabled(True)
self.comseting.pushButton.setText("close")
def confFormOpen(self):
self.comseting.comboBox_2.setEnabled(True)
self.comseting.comboBox.setEnabled(True)
self.comseting.comboBox_3.setEnabled(True)
self.comseting.comboBox_4.setEnabled(True)
self.comseting.comboBox_5.setEnabled(True)
self.comseting.pushButton.setText("Open")
def Temperaturetest(self):
print "hello world."
#self.__sendBufcmd()
def periodTask(self):
# Init time
now = datetime.now()
# First next run time
period = timedelta(minutes=0.1)
next_time = now + period
strnext_time = next_time.strftime('%Y-%m-%d %H:%M:%S')
while ff==True:
# Get system current time
iter_now = datetime.now()
iter_now_time = iter_now.strftime('%Y-%m-%d %H:%M:%S')
if str(iter_now_time) == str(strnext_time):
# Call task func
self.sendBufcmd()
# Get next iteration time
iter_time = iter_now + period
strnext_time = iter_time.strftime('%Y-%m-%d %H:%M:%S')
# Continue next iteration
def __TemperatureTestStart(self):
#c45.periodTask().start()
global ff
ff = True
self.thread_periodTask = threading.Timer(1, self.periodTask)
self.thread_periodTask.setDaemon(True)
self.thread_periodTask.start()
self.textBrowser_DR.append(str("Temperature Test Start"))
def __TemperatureTestStop(self):
global ff
ff = False
self.textBrowser_DR.append(str("Temperature Test Stop"))
def getData(self):
return self.CMDTextEdit.toPlainText().toUtf8().data()
def onRecvData(self,data):
bytes = len(data)
data = Util.toVisualHex(data)
data = data.replace('\n', '<br/>')
self.textBrowser_DR.append('<b>Recv</b> @%s<br/><font color="red">%s</font><br/><br/>'
% (ctime(), data))
def __readCPStatus(self):
ReadCPStatusCMD = [0xF204, 0x0003]
c = Util.dataCHK(ReadCPStatusCMD, 2)
ReadCPStatusCMD.append(Util.dataCHK(ReadCPStatusCMD, 2))
self.__sendcmd(ReadCPStatusCMD)
def __powerContrlcmd(self):
powerOffCMD = [0xF404, 0x0005,0x0001,0x0001]
if self.radioButton_Pon.isChecked():
self.__powerON()
if self.radioButton_Poff.isChecked():
self.__powerOff()
def __powerON(self):
powerOnCMD = [0xF604, 0x0005,0x0001,0x0001]
powerOnCMD.append(Util.dataCHK(powerOnCMD, 4))
self.__sendcmd(powerOnCMD)
def __powerOff(self):
powerOnCMD = [0xF604, 0x0005,0x0002,0x0002]
powerOnCMD.append(Util.dataCHK(powerOnCMD, 4))
self.__sendcmd(powerOnCMD)
def __sendcmd(self, data):
if not self.flags["__isopen__"]:
QtGui.QMessageBox.information(self, "Tips", u"请先打开串口")
return
_type ="hex"
self.__onSendcmd(data)
for i in r
没有合适的资源?快使用搜索试试~ 我知道了~
python + QT4 上位机开发
共318个文件
pyo:261个
py:19个
dll:10个
需积分: 36 66 下载量 89 浏览量
2018-01-09
15:12:15
上传
评论 2
收藏 12.39MB ZIP 举报
温馨提示
PYQT4开发的串口调试软件,代码清晰适合Python刚入门者学习,比较实用的工具
资源推荐
资源详情
资源评论
收起资源包目录
python + QT4 上位机开发 (318个子文件)
QtGui4.dll 10.2MB
python27.dll 3.24MB
QtCore4.dll 3.05MB
qtiff4.dll 350KB
qmng4.dll 272KB
qjpeg4.dll 234KB
qico4.dll 34KB
qgif4.dll 32KB
qsvg4.dll 25KB
qtga4.dll 24KB
SerCom_UiHandler.exe 677KB
cosl-label.jpg 4KB
cosl-label.jpg 4KB
cosl.jpg 2KB
cosl.jpg 2KB
SerCom_UiHandler.exe.log 30KB
mainwindow_ui 198B
logo.png 1KB
logo.png 1KB
SerCom_UiHandler.py 11KB
mainwindow.py 10KB
comm_config.py 6KB
comm_ui.py 5KB
SerialCom.py 2KB
c45.py 2KB
Util.py 1KB
comm_configtool.py 969B
setup.py 492B
mainframe.py 393B
PyQt4.QtCore.py 362B
PyQt4.QtGui.py 361B
unicodedata.py 361B
_hashlib.py 358B
pyexpat.py 357B
_ctypes.py 357B
select.py 356B
sip.py 353B
bz2.py 353B
mainwindow.pyc 8KB
comm_config.pyc 5KB
comm_ui.pyc 5KB
SerialCom.pyc 3KB
Util.pyc 3KB
SerCom_UiHandler.pyc 3KB
c45.pyc 2KB
comm_configtool.pyc 2KB
PyQt4.QtGui.pyd 7.49MB
PyQt4.QtCore.pyd 2.08MB
_hashlib.pyd 1.37MB
unicodedata.pyd 677KB
pyexpat.pyd 177KB
_ctypes.pyd 119KB
sip.pyd 98KB
bz2.pyd 92KB
select.pyd 13KB
locale.pyo 49KB
doctest.pyo 44KB
pdb.pyo 38KB
optparse.pyo 38KB
ElementTree.pyo 32KB
pickle.pyo 31KB
__init__.pyo 30KB
case.pyo 27KB
difflib.pyo 26KB
uiparser.pyo 26KB
qtproxies.pyo 24KB
subprocess.pyo 24KB
inspect.pyo 23KB
threading.pyo 23KB
calendar.pyo 21KB
serialposix.pyo 19KB
sre_parse.pyo 19KB
codecs.pyo 18KB
_abcoll.pyo 18KB
__init__.pyo 16KB
collections.pyo 16KB
properties.pyo 16KB
random.pyo 16KB
bdb.pyo 16KB
serialutil.pyo 16KB
os.pyo 14KB
tempfile.pyo 14KB
gettext.pyo 14KB
stringprep.pyo 13KB
serialwin32.pyo 12KB
weakref.pyo 12KB
sre_compile.pyo 12KB
string.pyo 12KB
heapq.pyo 11KB
sets.pyo 11KB
_strptime.pyo 11KB
tokenize.pyo 11KB
warnings.pyo 10KB
ntpath.pyo 9KB
copy.pyo 9KB
loader.pyo 9KB
suite.pyo 9KB
_weakrefset.pyo 9KB
UserDict.pyo 9KB
posixpath.pyo 8KB
共 318 条
- 1
- 2
- 3
- 4
资源评论
laoshumyang
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言基础-C语言编程基础之Leetcode编程题解之第30题串联所有单词的子串.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第29题两数相除.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第28题找出字符串中第一个匹配项的下标.zip
- 实验报告模板(1).docx
- C语言基础-C语言编程基础之Leetcode编程题解之第26题删除有序数组中的重复项.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第25题K个一组翻转链表.zip
- hnu计算机系统作业-计算机系统基础课程大作业.zip
- 树莓派app.apk
- C++的基于同态加密技术的匿名电子投票系统源码.zip
- SW建模格式图.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功