首页 > 编程语言 > 详细

Python serial

时间:2017-11-27 14:48:54      阅读:296      评论:0      收藏:0      [点我收藏+]
__init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None)
Parameters:

Raises:

  • ValueError – Will be raised when parameter are out of range, e.g. baud rate, data bits.
  • SerialException – In case the device can not be found or can not be configured.
 1 import serial
 2 import time
 3 
 4 
 5 # initialize the serial ports
 6 t = serial.Serial(com9,9600,timeout = 0.1)
 7 #write commond list, commond should be ended with ‘\n‘ or ‘\r‘
 8 cmd_list = [val?\r,temp?\r]
 9 a = ‘‘
10 
11 #t.close() # close port
12 #t.open() # open port
13 
14 print t.portstr #print port number
15 for idx2 in cmd_list:
16     n = t.write(idx2)
17     #print n  #
18     #s1 = t.readall()
19     s1 = t.readline()
20     #s1 = t.readlines()
21     print s1
22 
23 #t = serial.Serial(‘com8‘,9600,timeout = 0.1)
24 #for idx1 in cmd_list:
25 #    t.write(idx1)
26 #    start = time.clock()
27 #    while(True):
28 #        s = t.read(1)
29 #        a = a + s
30 #        if(str(s) == ‘\r‘):
31 #            break
32 #        now = time.clock()
33 #        if(now - start) > 2:
34 #            print ‘timeout‘
35 #            break
36 #    print a
37 #    a = ‘‘
38 
39 t.close()

 

Python serial

原文:http://www.cnblogs.com/njuptlwh/p/7903869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!