#!/usr/bin/python3 -u import os import sys import struct import serial from subprocess import Popen, PIPE, run f = open("subprocess.log", "w+") ser = serial.Serial('/dev/ttyUSB0', 115200) def flash(): run("JLinkExe flash.jlink", shell=True, check=True) def read(channel, l): if channel == 'ser': data = ser.read(l) elif channel == 'std': data = sys.stdin.read(l) else: raise Exception("read() complains: no sai channelino") if len(data) != l: raise Exception("could not read %d bytes of data (got %d)" % (l, len(data))) return data def write(channel, data): if channel == 'ser': l = ser.write(data) f.write("Data sent to serial: " + str(data) + "\n") elif channel == 'std': l = sys.stdout.write(data) else: raise Exception("write() complains: no sai channelino") if len(data) != l: raise Exception("could not write %d bytes of data (put %d)" % (len(data), l)) def obtain(channel): l = read(channel, 4) l = str.encode(l) f.write("Trying to read " + str(l) + "bytes from " + channel + "\n") (l, ) = struct.unpack("