Skip to content

Commit 27e0ca1

Browse files
committed
Updated for Python 3: change print statements to print functions
Added recognition for W65C134SXB prompt of '.' Removed extra linefeeds from output
1 parent 9213794 commit 27e0ca1

File tree

1 file changed

+64
-57
lines changed

1 file changed

+64
-57
lines changed

TerminalPython.py

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
11
##Simple Python Script that will interface with WDC's W65C134SXB and W65C265SXB Boards.
22
##You can use this as a start to customize the interface for your needs.
33
##NOTE: Change Line 14 to have the proper COM port or it will not work!
4+
## Updated for Python 3: change print statements to print functions
5+
## Added recognition for W65C134SXB prompt of '.'
6+
## Removed extra linefeeds from output
47
##import serial lib
58
##import msvcrt
69
import serial
710
import io
811
import time
912

1013
try:
11-
from msvcrt import getch
14+
from msvcrt import getch
1215
except ImportError:
13-
''' we're not on Windows, so we try the Unix-like approach '''
16+
''' we're not on Windows, so we try the Unix-like approach '''
1417

15-
def getch( ):
16-
import sys, tty, termios
17-
fd = sys.stdin.fileno( )
18-
old_settings = termios.tcgetattr(fd)
19-
try:
20-
tty.setraw(fd)
21-
ch = sys.stdin.read(1)
22-
finally:
23-
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
24-
return ch
18+
def getch():
19+
import sys
20+
import tty
21+
import termios
22+
fd = sys.stdin.fileno()
23+
old_settings = termios.tcgetattr(fd)
24+
try:
25+
tty.setraw(fd)
26+
ch = sys.stdin.read(1)
27+
finally:
28+
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
29+
return ch
2530

2631
##open serial port
27-
print ("Welcome to WDC's 65xx Serial Monitor in Python");
28-
print ("Press the reset button on your board to start reading serial data from the board");
29-
## For now the Serial Port Needs to be set manually. Change the line below to your COMXX port
30-
ser = serial.Serial("/dev/tty.usbserial-A703XC1I", 9600,timeout=1)
32+
print("Welcome to WDC's 65xx Serial Monitor in Python")
33+
print("Press the reset button on your board to start reading serial data from the board")
34+
## For now the Serial Port Needs to be set manually. Change the line below to
35+
## your COMXX port
36+
ser = serial.Serial("/dev/tty.usbserial-A703XC1I", 9600, timeout=1)
3137
ser.flushInput()
3238
ser.flushOutput()
3339
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
3440
readser = 1
3541
#while loop to read in serial data
3642
#line will autofeed if reset is not pushed at beginning
3743
while readser == 1:
38-
hello = sio.readline()
39-
#testing
40-
#
41-
if hello:
42-
if "Copyright 1995" in hello:
43-
hello = hello.replace("1995", "1995-2014"); ##Just an example of replacing text. Not needed.
44-
print hello;
45-
elif hello.strip() == '>':
46-
readser = 0
47-
print ("Enter a command. For a list of commands press h");
48-
print hello;
49-
writedata = getch()
50-
ser.write(writedata)
51-
readser = 1
52-
elif "BB:AAAA" in hello:
53-
readser = 0
54-
print hello;
55-
print ("Type in a 2 digit Bank Address - Press Enter");
56-
writedata = raw_input()
57-
if len(writedata) == 2:
58-
ser.write(writedata)
59-
readser = 1
60-
else:
61-
print ("Please re-enter the 2 digit hex Bank Address and press enter");
62-
writedata = raw_input()
63-
readser = 1
64-
elif hello.endswith(':'):
65-
readser = 0
66-
print hello;
67-
print ("Type in a 4 digit Address - Press Enter");
68-
writedata = raw_input()
69-
if len(writedata) == 4:
70-
ser.write(writedata)
71-
readser = 1
72-
else:
73-
print ("Please re-enter the 4 digit hex address and press enter");
74-
writedata = raw_input()
75-
readser = 1
76-
else:
77-
print hello;
44+
hello = sio.readline()
45+
#testing
46+
#
47+
if hello:
48+
if "Copyright 1995" in hello:
49+
hello = hello.replace("1995", "1995-2014") ##Just an example of replacing text. Not needed.
50+
print(hello.rstrip())
51+
# The W65C134SXB uses '.' for it's Monitor ROM prompt
52+
elif (hello.strip() == '>' | hello.strip() == '.'):
53+
readser = 0
54+
print("Enter a command. For a list of commands press h")
55+
print(hello.rstrip())
56+
writedata = getch()
57+
ser.write(writedata)
58+
readser = 1
59+
elif "BB:AAAA" in hello:
60+
readser = 0
61+
print(hello.rstrip())
62+
print("Type in a 2 digit Bank Address - Press Enter")
63+
writedata = raw_input()
64+
if len(writedata) == 2:
65+
ser.write(writedata)
66+
readser = 1
67+
else:
68+
print("Please re-enter the 2 digit hex Bank Address and press enter")
69+
writedata = raw_input()
70+
readser = 1
71+
elif hello.endswith(':'):
72+
readser = 0
73+
print(hello.rstrip())
74+
print("Type in a 4 digit Address - Press Enter")
75+
writedata = raw_input()
76+
if len(writedata) == 4:
77+
ser.write(writedata)
78+
readser = 1
79+
else:
80+
print("Please re-enter the 4 digit hex address and press enter")
81+
writedata = raw_input()
82+
readser = 1
83+
else:
84+
print(hello.rstrip())
7885

7986
##close serial connection
8087
ser.close()
81-
print ("Closing out!");
88+
print("Closing out!")

0 commit comments

Comments
 (0)