Skip to content

Commit 8493237

Browse files
committed
Needed 'or' statement, not bitwise '|'
1 parent 27e0ca1 commit 8493237

File tree

1 file changed

+88
-88
lines changed

1 file changed

+88
-88
lines changed

TerminalPython.py

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
1-
##Simple Python Script that will interface with WDC's W65C134SXB and W65C265SXB Boards.
2-
##You can use this as a start to customize the interface for your needs.
3-
##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
7-
##import serial lib
8-
##import msvcrt
9-
import serial
10-
import io
11-
import time
12-
13-
try:
14-
from msvcrt import getch
15-
except ImportError:
16-
''' we're not on Windows, so we try the Unix-like approach '''
17-
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
30-
31-
##open serial port
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)
37-
ser.flushInput()
38-
ser.flushOutput()
39-
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
40-
readser = 1
41-
#while loop to read in serial data
42-
#line will autofeed if reset is not pushed at beginning
43-
while readser == 1:
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())
85-
86-
##close serial connection
87-
ser.close()
88-
print("Closing out!")
1+
##Simple Python Script that will interface with WDC's W65C134SXB and W65C265SXB Boards.
2+
##You can use this as a start to customize the interface for your needs.
3+
##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
7+
##import serial lib
8+
##import msvcrt
9+
import serial
10+
import io
11+
import time
12+
13+
try:
14+
from msvcrt import getch
15+
except ImportError:
16+
''' we're not on Windows, so we try the Unix-like approach '''
17+
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
30+
31+
##open serial port
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("COM79", 9600, timeout=1)
37+
ser.flushInput()
38+
ser.flushOutput()
39+
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
40+
readser = 1
41+
#while loop to read in serial data
42+
#line will autofeed if reset is not pushed at beginning
43+
while readser == 1:
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() == '>' or 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())
85+
86+
##close serial connection
87+
ser.close()
88+
print("Closing out!")

0 commit comments

Comments
 (0)