我一直在寻找这个,但无法得到一个很好的答案。检测pyserial中的文件结尾python3
我必须通过两个PC之间的COM端口发送文件。
但我不知道如何检测文件的结尾。
在PC 1中,我使用teraTerm软件发送文件。
在PC 2中使用以下python代码。
文件发送后,我需要把一些消息,该文件是完整的。
import serial
ser = serial.Serial('COM1')
ser.flush_input_buffer()
file = open('file.txt','a') #open empty file for appending
while True:
receivedByte = ser.read() # read 1 byte
file.write(receivedByte)
if (#detect end of file):
break
print('file received')
请注意:PC是Windows 8.1,Pyserial,Python的3.4
请还建议为Linux文件