- 浏览: 615597 次
- 性别:
- 来自: 厦门
文章分类
最新评论
-
咖啡舞者:
现在在厦门工作还好吧。
2013换工作记 -
huih1984:
工作8年,算起来楼主和我差不多岁数啊, ,本人现在干着没有合同 ...
2013换工作记 -
无心流泪wan:
乘法法则规定复数的乘法按照以下的法则进行:设z1=a+bi,z ...
帮朋友做的一笔试(友元 运算符重载) -
我叫营长1:
谢谢,很详细呢
SharedPreferences 的用法 -
javalinjx:
挺有意思的。哈哈
2013换工作记
pySerial
Overview
This module encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux, BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named "serial" automatically selects the appropriate backend.It is released under a free software license, see LICENSE.txt for more details.
(C) 2001-2008 Chris Liechti cliechti@gmx.net
The project page on SourceForge and here is the SVN repository and the Download Page .
The homepage is on http://pyserial.sf.net/
Features
- same class based interface on all supported platforms
- access to the port settings through Python 2.2+ properties
- port numbering starts at zero, no need to know the port name in the user program
- port string (device name) can be specified if access through numbering is inappropriate
- support for different bytesizes, stopbits, parity and flow control with RTS/CTS and/or Xon/Xoff
- working with or without receive timeout
- file like API with "read" and "write" ("readline" etc. also supported)
- The files in this package are 100% pure Python. They depend on non standard but common packages on Windows (pywin32) and Jython (JavaComm). POSIX (Linux, BSD) uses only modules from the standard Python distribution)
- The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. (which are many times enabled for POSIX.) This makes this module universally useful.
Requirements
- Python 2.2 or newer
- pywin32 extensions on Windows
- "Java Communications" (JavaComm) or compatible extension for Java/Jython
Installation
from source
Extract files from the archive, open a shell/console in that directory and let Distutils do the rest:python setup.py install
The files get installed in the "Lib/site-packages" directory.
easy_install
An EGG is available from the Python Package Index: http://pypi.python.org/pypi/pyserialeasy_install pyserial
windows installer
There is also a Windows installer for end users. It is located in the Download PageDevelopers may be interested to get the source archive, because it contains examples and the readme.
Short introduction
Open port 0 at "9600,8,N,1", no timeout<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
>>> import serial >>> ser = serial.Serial(0) # open first serial port >>> print ser.portstr # check which port was really used >>> ser.write("hello") # write a string >>> ser.close() # close portOpen named port at "19200,8,N,1", 1s timeout
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
>>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) >>> x = ser.read() # read one byte >>> s = ser.read(10) # read up to ten bytes (timeout) >>> line = ser.readline() # read a '\n' terminated line >>> ser.close()Open second port at "38400,8,E,1", non blocking HW handshaking
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
>>> ser = serial.Serial(1, 38400, timeout=0, ... parity=serial.PARITY_EVEN, rtscts=1) >>> s = ser.read(100) # read up to one hundred bytes ... # or as much is in the bufferGet a Serial instance and configure/open it later
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
>>> ser = serial.Serial() >>> ser.baudrate = 19200 >>> ser.port = 0 >>> ser Serial<id=0xa81c10, open=False>(port='COM1', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0) >>> ser.open() >>> ser.isOpen() True >>> ser.close() >>> ser.isOpen() FalseBe carefully when using "readline". Do specify a timeout when opening the serial port otherwise it could block forever if no newline character is received. Also note that "readlines" only works with a timeout. "readlines" depends on having a timeout and interprets that as EOF (end of file). It raises an exception if the port is not opened correctly.
Do also have a look at the example files in the examples directory in the source distribution or online.
Examples
Please look in the SVN Repository. There is an example directory where you can find a simple terminal and more.http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/examples/
Parameters for the Serial class
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->ser = serial.Serial( port=None, # number of device, numbering starts at # zero. if everything fails, the user # can specify a device string, note # that this isn't portable anymore # if no port is specified an unconfigured # an closed serial port object is created baudrate=9600, # baud rate bytesize=EIGHTBITS, # number of databits parity=PARITY_NONE, # enable parity checking stopbits=STOPBITS_ONE, # number of stopbits timeout=None, # set a timeout value, None for waiting forever xonxoff=0, # enable software flow control rtscts=0, # enable RTS/CTS flow control interCharTimeout=None # Inter-character timeout, None to disable )The port is immediately opened on object creation, if a port is given. It is not opened if port is None.
Options for read timeout:
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
timeout=None # wait forever timeout=0 # non-blocking mode (return immediately on read) timeout=x # set timeout to x seconds (float allowed)
Methods of Serial instances
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->open() # open port close() # close port immediately setBaudrate(baudrate) # change baud rate on an open port inWaiting() # return the number of chars in the receive buffer read(size=1) # read "size" characters write(s) # write the string s to the port flushInput() # flush input buffer, discarding all it's contents flushOutput() # flush output buffer, abort output sendBreak() # send break condition setRTS(level=1) # set RTS line to specified logic level setDTR(level=1) # set DTR line to specified logic level getCTS() # return the state of the CTS line getDSR() # return the state of the DSR line getRI() # return the state of the RI line getCD() # return the state of the CD line
Attributes of Serial instances
Read Only:<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
portstr # device name BAUDRATES # list of valid baudrates BYTESIZES # list of valid byte sizes PARITIES # list of valid parities STOPBITS # list of valid stop bit widthsNew values can be assigned to the following attributes, the port will be reconfigured, even if it's opened at that time:
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
port # port name/number as set by the user baudrate # current baud rate setting bytesize # byte size in bits parity # parity setting stopbits # stop bit with (1,2) timeout # timeout setting xonxoff # if Xon/Xoff flow control is enabled rtscts # if hardware flow control is enabled
Exceptions
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->serial.SerialException
Constants
parity:<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
serial.PARITY_NONE serial.PARITY_EVEN serial.PARITY_ODDstopbits:
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
serial.STOPBITS_ONE serial.STOPBITS_TWObytesize:
<!-- /* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ .text .imp {font-weight: bold; color: red;} -->
serial.FIVEBITS serial.SIXBITS serial.SEVENBITS serial.EIGHTBITS
发表评论
-
自己的感想:如何在非纯软件公司做研发
2010-11-17 10:16 2257在这家公司挺多年的,公司是以硬件销售为主,也这个是 ... -
转 从我写程序那天起:我就没打算写程序
2010-08-31 16:23 1750序: 大约是前年的时 ... -
oracle自动备份脚本
2010-07-29 09:16 978具体参看附件 -
元宵节后上班
2010-03-01 16:23 1084在新岗位上工作一星期了,慢慢有点感觉了。今天早上经 ... -
Modem 安装指南.pdf
2009-10-16 08:13 1032MTK模块建立拔号上网的指南,有时可以用做检验模块GPRS拔号 ... -
是什么在阻碍移动公司电子渠道的发展
2009-09-28 18:01 1481如果从一个软件工程师的角度来分析这个问题,可能显得十分狭隘。但 ... -
嵌入式系统数据同步协议 SyncML 简介
2009-05-27 09:31 2212目前在嵌入式系 ... -
SubVersion服务器Windows安装指南
2009-05-18 16:32 2647SubVersion及TortoiseSVN下载 ... -
WinCVS 1.3.6.1简明操作指南
2009-05-18 13:59 2754作者:陈先波 邮件:turbochen@163.com ... -
MTK之LCD亮度调整测试代码块
2009-05-14 15:05 2773前一段的东西做完了准备要提交测试了,这次是第二版本 ... -
MTK打印之:定时器设计两式比较
2009-05-13 20:49 2267MTK打印之:定时器设计 ... -
如何使用Outlook Express拒收邮件
2009-05-13 15:07 1677我们公司有上bu ... -
使用StarUML建模
2009-05-09 15:40 4340http://javasso.cn/2009/04/29/%E ... -
Writing SMS Messages to Memory / Message Storage
2009-04-28 09:04 2267转自:http://www.developershome.co ... -
MTK电话本短信同步
2009-04-27 20:03 3534做MTK开发也有一段时间,最近做一个产品,其中有一个测试功能, ... -
设计模式趣解
2009-04-24 08:32 10871、FACTORY-工厂模式:追MM少不了请吃饭了,麦当劳的 ... -
我对acts as tree的理解及应用
2007-04-30 17:13 2876最近在看敏捷一书,把我对Acts as tree一节的理解写下 ...
相关推荐
Python串口通信是Python编程中一个重要的组成部分,特别...这个库对于进行Python的串口开发来说是不可或缺的工具,尤其对于那些需要在Windows系统上进行串口通信的项目,Pyserial-2.5.win32版本是一个可靠的解决方案。
安装pyserial-3.4.tar.gz步骤:下载pyserial-3.4.tar.gz并解压,在安装python并将python添加到环境变量中后,打开命令提示符窗口切换到解压pyserial-3.4.tar.gz的目录路径,然后输入python setup.py install,即可...
pySerial是一个强大的库,它为Python提供了跨平台的串口通信功能。本文将详细介绍如何使用pip来安装pySerial模块,以及pySerial的主要特性和使用方法。 首先,让我们来看看如何使用pip安装pySerial。pip是Python的...
本文将详细解析使用Python进行串口通信的上位机应用开发,结合给定的标签"python pyside2 pyserial",我们可以看到这个项目涉及到的技术栈。 首先,`Python`是一种高级编程语言,以其简洁的语法和丰富的库资源深受...
Python的`serial`模块,通常称为`pyserial`,是一个非常重要的工具,它允许开发者在Python程序中与串行端口进行通信。这个模块适用于各种应用场景,包括嵌入式设备控制、硬件测试、数据采集等。`pyserial`库不仅支持...
1. Python串口调试(pyserial库): Python的pyserial库是一个强大的工具,用于与各种串行设备进行通信。它允许开发者打开、配置和读写串口,适合于硬件调试。在"dw_pyserial_work.py"中,开发者可能利用pyserial的...
在这个项目中,我们将关注Python3在创建图形用户界面(GUI)和串口通信方面的应用。 Tkinter是Python的标准GUI库,它是与Tcl/Tk编程语言绑定的,为Python提供了一种简单且跨平台的方式来创建窗口应用。虽然Tkinter...
本文将深入探讨pyserial-2.5.win32版本,这个专门为Windows系统设计的Python串口模块。 首先,让我们明确什么是串口通信。串口通信,也称为串行通信,是一种数据传输方式,通过单个数据线逐位传输信息。它常用于...
《VB6串口通讯类:基于pyserial与win32api的实现》 在信息技术领域,串口通信是一种常见的设备间数据传输方式,尤其在嵌入式系统和工业自动化中广泛应用。本文将深入探讨如何在VB6(Visual Basic 6)环境中,利用...
RFID技术是一种非接触式的自动识别技术,通过射频信号自动识别目标对象并获取相关数据,而Python中的pyserial模块则提供了方便的接口来操作串口通信。 **pyserial模块详解:** pyserial是Python的一个第三方库,...
PySerial是Python编程语言中用于串行通信的一个重要模块,它使得在Python中控制串行端口变得极其简单。这个模块在Python 3.0及更高版本上运行良好,并且在Windows操作系统下,由于包含了`serialwin32.py`,我们无需...
python串口操作,使用python的pyserial实现,可进行hex转换发送,hex接收显示,如有不理解的地方,请参见博客:https://blog.csdn.net/absinjun/article/details/81407790
### Python使用pyserial进行串口通信的实例 在本文中,我们将详细介绍如何使用Python与`pyserial`库实现串口通信。此实例不仅适合初学者快速上手,也能为有一定基础的开发人员提供深入理解的机会。 #### 一、...
总的来说,这个"python3+qt4+pyserial 串口调试助手 串口波形显示"项目结合了Python3的编程能力,Qt4的界面设计,以及pyserial的串口通信功能,提供了一个实用的工具,帮助开发者和工程师更高效地进行串口设备的调试...
总的来说,“Serial2CSV_python字节数据_csv_串口_python_”这个项目展示了如何利用Python结合`pyserial`和`csv`库,实现串口数据的实时监控和存储。对于需要处理类似数据流的开发者,理解并学习这个脚本将大有裨益...
在本文中,我们将深入探讨Python的串口通信库PySerial以及如何使用它来创建串口调试工具。 PySerial是Python的一个扩展模块,专门用于处理串行通信。它提供了丰富的功能,如打开和关闭串口、发送和接收数据、设置...
对于Python,可以使用`pyserial`库。代码中还需包含读取和解析陀螺仪数据的逻辑。 4. **数据接收与解析**:当串口接收到数据时,根据JY-61的数据格式(例如ASCII或二进制)解码角度值。这可能涉及将接收到的字节...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装