3 from SerialPort_linux import *
5 # contains the last received checksum from a READ, WRITE or CHECKSUM command
9 time.sleep(0.01) # just to get sure, wait 10ms
15 sendByte((word >> 8) & 0xFF)
18 sendByte(dword & 0xFF)
19 sendByte((dword >> 8) & 0xFF)
20 sendByte((dword >> 16) & 0xFF)
21 sendByte((dword >> 24) & 0xFF)
24 return ord(tty.read())
29 last_checksum = recvByte()
30 last_checksum |= (recvByte() << 8)
32 def cmdREAD(address, size):
35 if (recvByte() != 0xF1):
38 if (recvByte() != 0x82):
40 # tell desired address and size
43 # get binary stream of data
45 for i in range(0, size):
46 data.append(recvByte())
51 def cmdWRITE(address, size, data):
54 if (recvByte() != 0xF1):
57 if (recvByte() != 0x83):
59 # tell desired address and size
62 # write binary stream of data
63 for i in range(0, size):
68 def cmdBAUDRATE(baudrate):
71 # send BAUDRATE command
73 if (recvByte() != 0xF1):
76 if (recvByte() != 0x86):
78 # send desired baudrate
79 sendByte(baudrate & 0xFF)
80 sendByte((baudrate >> 8) & 0xFF)
81 sendByte((baudrate >> 16) & 0xFF)
82 sendByte((baudrate >> 24) & 0xFF)
84 print "Initializing serial port..."
85 tty = SerialPort("/dev/ttyUSB0", 100, 9600)
87 print "Please press RESET on your 1337 board..."
95 except SerialPortException:
96 # timeout happened, who cares ;-)
99 print "OK, trying to set baudrate..."
103 tty = SerialPort("/dev/ttyUSB0", 100, 19200)
107 # write something to the begin of the IRAM
108 data = [255, 2, 3, 4]
109 print "Writing", data, "to the IRAM..."
110 cmdWRITE(0x00030000, 4, data)
111 print "Received Checksum:", last_checksum
114 print "Reading from the IRAM again..."
115 data2 = cmdREAD(0x00030000, 4)
116 print "Received data:", data2, "Checksum:", last_checksum