我是Python串行编程的新手。基本上,执行与在Putty或其他终端中执行的命令相同的命令。将命令“ dz 0x80000000 4096”运行到TiVa处理器后,从Putty获取输出,但不能使用下面编写的Python3.6.5程序。没有输出,就好像它没有编写命令一样。在运行write命令后,也没有将输出打印到屏幕上。
以下程序:
import logging
import serial
import serial.threaded
import threading
import time
timeout = time.time() + 15 #may have to adjust, 10 seconds from now
import sys
import csv
from datetime import datetime
ser= serial.Serial('COM19', baudrate = 115200,parity=serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,bytesize = serial.EIGHTBITS,rtscts = True,timeout = 2,writeTimeout = 5)
def getvalues():
ser.write(b'dz 0x80000000 4096') #printed 18, not sure if it ran the command?
IQ_data = ser.readline().decode('ascii')
return IQ_data
while(1):
with open("E:/HigherGround_Home/Pyserial_Gurb/log.txt","w") as f:
writer = csv.writer(f)
writer.writerow(getvalues())
if time.time() > timeout:
break
f.close()
有人可以帮助我让我的程序正确打印到文件吗?
谢谢, 古柏