graphWindow.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:serialplot 作者: crxguy52 项目源码 文件源码
def openSerial(self):
        #Set up the relationship between what the user enters and what the API calls for
        bytedic = {'5':serial.FIVEBITS,
                   '6':serial.SIXBITS,
                   '7':serial.SEVENBITS,
                   '8':serial.EIGHTBITS}
        bytesize = bytedic[str(self.root.variables['databits'])]

        paritydict = {'None':serial.PARITY_NONE,
                      'Even':serial.PARITY_EVEN,
                      'Odd' :serial.PARITY_ODD,
                      'Mark':serial.PARITY_MARK,
                      'Space':serial.PARITY_SPACE}
        parity=paritydict[self.root.variables['parity']]

        stopbitsdict = {'1':serial.STOPBITS_ONE,
                        '2':serial.STOPBITS_TWO}
        stopbits = stopbitsdict[str(self.root.variables['stopbits'])]

        #Open the serial port given the settings, store under the root
        if os.name == 'nt':
            port = self.root.variables['COMport'][0:5].strip()
            self.root.ser = serial.Serial(\
                port=port,\
                baudrate=str(self.root.variables['baud']),\
                bytesize=bytesize, parity=parity, stopbits=stopbits, timeout=0.5) 
        else:
            first_space = self.root.variables['COMport'].index(' ')
            port = self.root.variables['COMport'][0:first_space].strip()
            # Parameters necessary due to https://github.com/pyserial/pyserial/issues/59
            self.root.ser = serial.Serial(\
                port=port,\
                baudrate=str(self.root.variables['baud']),\
                bytesize=bytesize, parity=parity, stopbits=stopbits, timeout=0.5, rtscts=True, dsrdtr=True) 
        io.DEFAULT_BUFFER_SIZE = 5000

        #Purge the buffer of any previous data
        if float(serial.VERSION[0:3]) < 3:
            #If we're executing with pySerial 2.x
            serial.Serial.flushInput(self.root.ser)
            serial.Serial.flushOutput(self.root.ser)
        else:
            #Otherwise we're using pySerial 3.x
            serial.Serial.reset_input_buffer(self.root.ser)
            serial.Serial.reset_output_buffer(self.root.ser)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号