forked from WesternDesignCenter/TerminalPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerminalPython.py
88 lines (84 loc) · 3.08 KB
/
TerminalPython.py
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
88
##Simple Python Script that will interface with WDC's W65C134SXB and W65C265SXB Boards.
##You can use this as a start to customize the interface for your needs.
##NOTE: Change Line 14 to have the proper COM port or it will not work!
## Updated for Python 3: change print statements to print functions
## Added recognition for W65C134SXB prompt of '.'
## Removed extra linefeeds from output
##import serial lib
##import msvcrt
import serial
import io
import time
try:
from msvcrt import getch
except ImportError:
''' we're not on Windows, so we try the Unix-like approach '''
def getch():
import sys
import tty
import termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
##open serial port
print("Welcome to WDC's 65xx Serial Monitor in Python")
print("Press the reset button on your board to start reading serial data from the board")
## For now the Serial Port Needs to be set manually. Change the line below to
## your COMXX port
ser = serial.Serial("COM79", 9600, timeout=1)
ser.flushInput()
ser.flushOutput()
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
readser = 1
#while loop to read in serial data
#line will autofeed if reset is not pushed at beginning
while readser == 1:
hello = sio.readline()
#testing
#
if hello:
if "Copyright 1995" in hello:
hello = hello.replace("1995", "1995-2014") ##Just an example of replacing text. Not needed.
print(hello.rstrip())
# The W65C134SXB uses '.' for it's Monitor ROM prompt
elif (hello.strip() == '>' or hello.strip() == '.'):
readser = 0
print("Enter a command. For a list of commands press h")
print(hello.rstrip())
writedata = getch()
ser.write(writedata)
readser = 1
elif "BB:AAAA" in hello:
readser = 0
print(hello.rstrip())
print("Type in a 2 digit Bank Address - Press Enter")
writedata = raw_input()
if len(writedata) == 2:
ser.write(writedata)
readser = 1
else:
print("Please re-enter the 2 digit hex Bank Address and press enter")
writedata = raw_input()
readser = 1
elif hello.endswith(':'):
readser = 0
print(hello.rstrip())
print("Type in a 4 digit Address - Press Enter")
writedata = raw_input()
if len(writedata) == 4:
ser.write(writedata)
readser = 1
else:
print("Please re-enter the 4 digit hex address and press enter")
writedata = raw_input()
readser = 1
else:
print(hello.rstrip())
##close serial connection
ser.close()
print("Closing out!")