串口读取putty和pyserial之间的区别

时间:2017-03-03 19:36:11

标签: python python-2.7 putty pyserial

当我从putty读取数据时,我正在从串口读取一些数据,输出结果如下:

X7_SEM_V3_6
SC 01
FS 09
ICAP OK
RDBK OK
INIT OK
SC 02
O>

但是当我使用pyserial在python中编写代码时,它没有读取最后一行O>

X7_SEM_V3_6
SC 01
FS 09
ICAP OK
RDBK OK
INIT OK
SC 02

这是代码;请有人有任何知识,请分享

#!/usr/bin/python

import itertools
import fileinput
import serial, time
import binascii
ser = serial.Serial()
ser.port = "/dev/ttyUSB3"
ser.baudrate = 38400
ser.bytesize = serial.EIGHTBITS 
ser.parity = serial.PARITY_NONE 
ser.stopbits = serial.STOPBITS_ONE              
ser.xonxoff = False    
ser.rtscts = False    
ser.dsrdtr = False  
number_address = 1341602
number_char = 9  
timeout=1

count =0
f=open('lut100.txt','r')

try: 
    ser.open()
except Exception, e:
    print "error open serial port: " + str(e)
    exit()


if ser.isOpen():


         ser.flushInput()
         ser.flushOutput()
# reading        
         max_packet = 20
         while True:

            byteData = ser.read_until('\r',max_packet)
            newdata=str(byteData)
            print newdata.strip() 
else:
    print "cannot open serial port "

0 个答案:

没有答案