python简单程序读取串口信息的方法

yipeiwu_com7年前Python基础

本文实例讲述了python简单程序读取串口信息的方法。分享给大家供大家参考。具体分析如下:

这段代码需要调用serial模块,通过while循环不断读取串口数据

import time
import serial
ser = serial.Serial( #下面这些参数根据情况修改
  port='COM1',
  baudrate=9600,
  parity=serial.PARITY_ODD,
  stopbits=serial.STOPBITS_TWO,
  bytesize=serial.SEVENBITS
)
data = ''
while ser.inWaiting() > 0:
  data += ser.read(1)
if data != '':
  print data

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python 加密的实例详解

 Python 加密的实例详解 hashlib支持md5,sha1,sha256,sha384,sha512,用法和md5一样  import hashlib...

python各种语言间时间的转化实现代码

一 基本知识 millisecond 毫秒 microsecond 微秒 nanosecond 纳秒 1秒=1000毫秒 1毫秒=1000微秒 1微秒=1000纳秒 二 perl pe...

Python 随机生成中文验证码的实例代码

python代码复制代码 代码如下: # -*- coding: utf-8 -*-  import Image,ImageDraw,ImageFont &nbs...

python类中super()和__init__()的区别

单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(self): print 'Base create'...

Python通过调用有道翻译api实现翻译功能示例

本文实例讲述了Python通过调用有道翻译api实现翻译功能。分享给大家供大家参考,具体如下: 通过调用有道翻译的api,实现中译英、其他语言译中文 Python代码: # codi...