-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsram.py
More file actions
executable file
·89 lines (67 loc) · 1.5 KB
/
sram.py
File metadata and controls
executable file
·89 lines (67 loc) · 1.5 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import serial
import time
import sys
import getopt
import string
from xmodem import XMODEM
print "Aria Loader - ISP utility for the Aria Module"
print "Version: 0.02"
filename = "binaries/at91sam9x5ek-sdcardboot-3.1.bin"
serialdevice = "/dev/ttyUSB0"
#Read the original executable file to send
try:
f = open(filename,'rb')
buffer = f.read()
f.close()
except:
print "Binary file not readable"
#Open the serial port
ser = serial.Serial(
port=serialdevice,
baudrate=115200,
timeout=1,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.flushInput()
#Define the getc and putc function required from the
#xmodem module
txbyte=0
def getc(size, timeout=1):
data = ser.read(size)
return data
def putc(data, timeout=1):
global txbyte
ser.write(data)
txbyte=txbyte+len(data)
return len(data)
x = XMODEM(getc, putc)
while True:
ser.flushInput()
ser.write('#')
rxchars = ser.read(3)
print rxchars
if rxchars.find('>')>0:
break
ser.flushInput()
cmdstring = "N#"
print "Send: [" + cmdstring + "]"
ser.write(cmdstring)
ser.read(2)
cmdstring = "S300000,#"
print "Send: [" + cmdstring + "]"
ser.write(cmdstring)
print "Send file %s in XModem" % filename
stream = open(filename, 'rb')
x.send(stream)
stream.close()
print "txbyte=%d" % txbyte
cmdstring = "G300000#"
print "Send: [" + cmdstring + "]"
ser.write(cmdstring)
print "Characters received from the Aria module (type Ctrl-C to exit)"
while True:
s = ser.read(1)
sys.stdout.write(s)
ser.close()