2013/06/17

PySide, PySerial

import sys
from PySide.QtCore import *
from PySide.QtGui import *
import serial

class TB_Form01(QDialog):
    def __init__(self, parent = None):
        super(TB_Form01, self).__init__(parent)
     
        self.edit = QLineEdit("Write char to send")
        self.button = QPushButton("Send to MCU")

        layout = QVBoxLayout()
        layout.addWidget(self.edit)
        layout.addWidget(self.button)

        self.setLayout(layout)
        self.button.clicked.connect(self.sendSerial)

    def sendSerial(self):
        ch_232 = self.edit.text()
        ch_232 = ch_232.encode('ascii')
        ser.write(ch_232)
        ser.write('\r\n')
        ch_232 = ser.read()
        while ch_232 != '>':
            ch_232 = ser.read()
            sys.stdout.write(ch_232)

if __name__ == '__main__':
    ser=serial.Serial(63,115200)
    app = QApplication(sys.argv)
    form = TB_Form01()
    form.show()

    sys.exit(app.exec_())

댓글 없음:

댓글 쓰기