标签:des lin seve com ast with readline lock character
Raises:
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()
标签:des lin seve com ast with readline lock character
原文地址:http://www.cnblogs.com/njuptlwh/p/7903869.html