我有一个python代码,可以从Artix-7 FPGA板的串口读取一些数据。然后在阅读之后,假设将一些9位十六进制数的数据写入端口,它做得很好,但问题是在每次写入之后首先读取所有文本文件然后递增并且我的文本文件的大小太大了1348065行。
这里的代码请引导某人。
function showDetails(cards, id) {
return cards.find(function(card) {
return card.id === id;
});
}
我的预期输出看起来像
#!/usr/bin/python
import serial, time
from addresstable import *
import binascii
ser = serial.Serial()
ser.port = "/dev/ttyUSB1"
ser.baudrate = 38400
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.xonxoff = False
ser.rtscts = False
ser.dsrdtr = False
number_address = 1341602
number_char = 9
timeout=1
#f=open('lut.txt','r')
try:
ser.open()
except Exception, e:
print "error open serial port: " + str(e)
exit()
if ser.isOpen():
try:
ser.flushInput()
ser.flushOutput()
# reading
max_packet = 20
lines = 0
while True:
byteData = ser.read_until('\r',max_packet)
newdata=str(byteData)
print newdata.strip()
ser.write('I')
time.sleep(0.01)
# writing
with open('adder-sem-address-sen0.txt', 'r') as f:
for line in f.readlines():
#print line
ser.write('N')
time.sleep(0.01)
ser.write(' ')
time.sleep(0.01)
ser.write('C')
time.sleep(0.01)
for i in line:
newdata=i
ser.write(newdata)
time.sleep(0.01)
time.sleep(1)
except Exception, e1:
print "error communicating...: " + str(e1)
else:
print "cannot open serial port "
并继续,它会做同样的事情,但在每行读取之后,它会整个文本文件的红色比读取下一行