我一直在尋找這個,但無法得到一個很好的答案。檢測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文件