我正在尝试以字节格式读取来自串口的jpg图像数据。由于jpg以FF / D8开头并以FF / D9结束,我认为我应该读取每个字节值并开始/停止将字节写入文件(如果它是这些值中的1个)?这是最好的方法吗?如果是这样,我如何检查字节值?
import serial
import sys
outf = open("image1.jpg", 'w')
ser = serial.Serial('/dev/ttyACM0', 115200)
while True:
c = ser.read() # reading a byte here
#check c for FF/D8 or FF/D9?
if c == ?
#write to file here?