Python 串口设备应用
1. Python 串口设备应用
简述
1.1. 线程轮寻
风尘无限 <tianyu263@163.com>
-- 分享
就是打开串口后,启动一个线程来监听串口数据的进入,有数据时,就做数据的处理(也可以发送一个事件,并携带接收到的数据)。
Toggle line numbers
1
2 #coding=gb18030
3
4 import sys,threading,time;
5 import serial;
6 import binascii,encodings;
7 import re;
8 import socket;
9
10 class ReadThread:
11 def __init__(self, Output=None, Port=0, Log=None, i_FirstMethod=True):
12 self.l_serial = None;
13 self.alive = False;
14 self.waitEnd = None;
15 self.bFirstMethod = i_FirstMethod;
16 self.sendport = '';
17 self.log = Log;
18 self.output = Output;
19 self.port = Port;
20 self.re_num = None;
21
22 def waiting(self):
23 if not self.waitEnd is None:
24 self.waitEnd.wait();
25
26 def SetStopEvent(self):
27 if not self.waitEnd is None:
28 self.waitEnd.set();
29 self.alive = False;
30 self.stop();
31
32 def start(self):
33 self.l_serial = serial.Serial();
34 self.l_serial.port = self.port;
35 self.l_serial.baudrate = 9600;
36 self.l_serial.timeout = 2;
37
38 self.re_num = re.compile('\d');
39
40 try:
41 if not self.output is None:
42 self.output.WriteText(u'打开通讯端口\r\n');
43 if not self.log is None:
44 self.log.info(u'打开通讯端口');
45 self.l_serial.open();
46 except Exception, ex:
47 if self.l_serial.isOpen():
48 self.l_serial.close();
49
50 self.l_serial = None;
51
52 if not self.output is None:
53 self.output.WriteText(u'出错:\r\n %s\r\n' % ex);
54 if not self.log is None:
相关文档:
Python作为一种功能强大且通用的编程语言而广受好评,它具有非常清晰的语法特点,适用于多种操作系统,目前在国际上非常流行,正在得到越来越多的应用。
下面就让我们一起来看看它的强大功能:
Python(派森),它是一个简单的、解释型的、交互式的、可移植的、面向对象的超高级语言。这就是对Python ......
在paramiko中使用用户名和密码通过sftp传输文件,不使用key文件。
import getpass
import select
import socket
import traceback
import paramiko
def putfile():
#import interactive
# setup logging
paramiko.util.log_to_file('demo.log')
username = username
hostname = hostname
......
python 中minidom解析xml
2009年06月26日 星期五 08:40
下面只列出一些常用的方法属性,如果要查看更多的方法, 可以去看文件minidom如何实现的。
获得Document对象
法一:
import xml.dom.minidom as m_dom
doc1 = m_dom.getDOMImplementation().createDocument(None, "root1", None)
doc1.documentElement.toxml(e ......
1、下载oracle软件
http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
oracle-instantclient-basic-10.2.0.4-1.i386.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
oracle-instantclient-devel-10.2.0.4-1.i386.rpm
2、安装rpm包
rpm -ivh oracle-instantclient-basic-10.2.0.4 ......
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 re ......