本帖最后由 YDCMAN 于 2017-2-20 16:05 编辑
谢谢楼主热心解答!
原因找到了,是由于LINUX系统和window系统对串口设备编号不一样,在window下是'COMX'参照解释帖子:http://www.360doc.com/content/11/0901/18/7585456_145056768.shtml
http://zhray2k.blog.163.com/blog/static/260282020111110115231245/
解决方法,在楼主原先的程序上进行如下:
#打开串口操作
def SciOpenButton_Click(self):
clickstatus = self.sciopenButton.isChecked()
if clickstatus:
#得到串口的设置参数
#comread = int(self.portcomtext.text())-1 #端口类型,在linux中为int,在windows中为string
comread = str(self.portcomtext.text()) #端口类型,在linux中为int,在windows中为string
comread='COM'+comread
#print comread
bandrate = int(self.baudratecombo.currentText())
databit = SERIAL_DATABIT_ARRAY[self.databitcombo.currentIndex()]
stopbit = SERIAL_STOPBIT_ARRAY[self.stopbitcombo.currentIndex()]
checkbit = SERIAL_CHECKBIT_ARRAY[self.checkbitcombo.currentIndex()]
print bandrate
print databit
print stopbit
print checkbit
#打开串口
try:
self._serial = serial.Serial(comread)
self._serial.baudrate = bandrate
self._serial.bytesize = databit
self._serial.parity = checkbit
self._serial.stopbits = stopbit
except (OSError, serial.SerialException):
QtGui.QMessageBox.warning(None,u"端口警告",u"端口无效或者不存在", QtGui.QMessageBox.Ok)
print u'测试文字MARK'
|