-
Notifications
You must be signed in to change notification settings - Fork 1
/
pro93-write
executable file
·61 lines (54 loc) · 1.36 KB
/
pro93-write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import serial
import time
import sys
import datetime
import argparse
parser = argparse.ArgumentParser(description='writes an image.')
parser.add_argument('infile', help='writes an image out')
args = parser.parse_args()
serial_options = {
'port':'/dev/ttyUSB0',
'baudrate':4800,
'bytesize':8,
'parity':'O',
'stopbits':2,
'timeout':None,
'xonxoff':False,
'rtscts':False,
'dsrdtr':True
}
preamble = bytes.fromhex('a5' * 50)
preamble2 = bytes.fromhex('01991352')
image = None
with open(args.infile, "rb") as f:
image = f.read()
if image is None:
print("No image read")
sys.exit(1)
# Reverse the image
image = image[::-1]
error_count = 0
with serial.Serial(**serial_options) as port:
port.write(preamble)
print(port.read(50).hex())
time.sleep(0.1)
port.write(preamble2)
print(port.read(4).hex())
time.sleep(1)
for i in range(633):
s = i * 32
e = s + 32
section = image[s:e]
#print(f"S {s} {e} ")
#print("W " + section.hex())
port.write(section)
time.sleep(0.1)
readback = port.read(32)
#print("R " + readback.hex())
if section != readback:
print("ERROR! readback != written")
error_count += 1
print(f"{i} of 633 written")
if error_count > 0:
print(f"Errors: {error_count}")