mirror of
https://github.com/rzzzwilson/pymlac.git
synced 2025-06-10 09:32:41 +00:00
New amalgamated PtrPtp device
This commit is contained in:
@@ -55,7 +55,6 @@ class PtrPtp(object):
|
|||||||
self.device_use = None
|
self.device_use = None
|
||||||
self.device_motor_on = False
|
self.device_motor_on = False
|
||||||
self.device_open_file = None
|
self.device_open_file = None
|
||||||
self.device_open_file = None
|
|
||||||
self.device_filename = None
|
self.device_filename = None
|
||||||
self.device_ready = False
|
self.device_ready = False
|
||||||
|
|
||||||
@@ -93,15 +92,10 @@ class PtrPtp(object):
|
|||||||
if self.device_use == self.InUsePTP:
|
if self.device_use == self.InUsePTP:
|
||||||
raise RuntimeError("ptr_dismount: Can't dismount PTR file, being used as PTP")
|
raise RuntimeError("ptr_dismount: Can't dismount PTR file, being used as PTP")
|
||||||
|
|
||||||
self.device_use = None
|
|
||||||
self.device_motor_on = False
|
|
||||||
self.device_ready = False
|
|
||||||
if self.device_filename:
|
if self.device_filename:
|
||||||
self.device_open_file.close()
|
self.device_open_file.close()
|
||||||
self.device_open_file = None
|
|
||||||
self.device_filename = None
|
self.reset()
|
||||||
self.ptr_at_eof = True
|
|
||||||
self.ptr_value = self.PtrEOF
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Turn papertape reader motor on."""
|
"""Turn papertape reader motor on."""
|
||||||
@@ -196,14 +190,10 @@ class PtrPtp(object):
|
|||||||
if self.device_use == self.InUsePTR:
|
if self.device_use == self.InUsePTR:
|
||||||
raise RuntimeError("ptp_dismount: Can't dismount PTP file, being used as PTR")
|
raise RuntimeError("ptp_dismount: Can't dismount PTP file, being used as PTR")
|
||||||
|
|
||||||
self.device_motor_on = False
|
|
||||||
self.device_ready = False
|
|
||||||
if self.ptp_filename:
|
if self.ptp_filename:
|
||||||
self.device_open_file.close()
|
self.device_open_file.close()
|
||||||
self.device_open_file = None
|
|
||||||
self.ptp_filename = None
|
self.reset()
|
||||||
self.ptp_at_eof = True
|
|
||||||
self.ptp_value = self.PtrEOF
|
|
||||||
|
|
||||||
def punch(self, value):
|
def punch(self, value):
|
||||||
"""Write byte to papertape file.
|
"""Write byte to papertape file.
|
||||||
@@ -216,7 +206,7 @@ class PtrPtp(object):
|
|||||||
|
|
||||||
self.device_ready = False
|
self.device_ready = False
|
||||||
self.device_cycle_count = self.PtpNotReadyCycles
|
self.device_cycle_count = self.PtpNotReadyCycles
|
||||||
self.device_open_file.write(struct.pack('1B', value))
|
self.device_open_file.write(value)
|
||||||
|
|
||||||
def ptp_tick(self, cycles):
|
def ptp_tick(self, cycles):
|
||||||
"""Called to push PTP state along.
|
"""Called to push PTP state along.
|
||||||
|
|||||||
@@ -15,14 +15,22 @@ where <options> is zero or more of:
|
|||||||
# 2. writing test *.ptp files which we mount and read
|
# 2. writing test *.ptp files which we mount and read
|
||||||
|
|
||||||
|
|
||||||
import Ptr
|
import os
|
||||||
import Ptp
|
|
||||||
|
import PtrPtp
|
||||||
|
|
||||||
|
|
||||||
# module global constants
|
# module global constants
|
||||||
PtrFilename = '_#PTR#_.ptp'
|
PtrFilename = '_#PTR#_.ptp'
|
||||||
PtpFilename = '_#PTP#_.ptp'
|
PtpFilename = '_#PTP#_.ptp'
|
||||||
|
|
||||||
|
Logfile = 'test_PTR_PTP.log'
|
||||||
|
|
||||||
|
|
||||||
|
def logger(*args):
|
||||||
|
msg = ' '.join(args)
|
||||||
|
with open(Logfile, 'ab') as fd:
|
||||||
|
fd.write(msg + '\n')
|
||||||
|
|
||||||
def read_no_tape(ptr):
|
def read_no_tape(ptr):
|
||||||
"""Read from device with no tape mounted."""
|
"""Read from device with no tape mounted."""
|
||||||
@@ -31,22 +39,23 @@ def read_no_tape(ptr):
|
|||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
if byte != 0377:
|
if byte != 0377:
|
||||||
print('Error')
|
print('Error')
|
||||||
ptr.tick(1000000) # wait a long time
|
ptr.ptr_tick(1000000) # wait a long time
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
if byte != 0377:
|
if byte != 0377:
|
||||||
print('Error')
|
print('Error')
|
||||||
|
|
||||||
# turn device on, still no tape
|
# turn device on, still no tape
|
||||||
ptr.start()
|
ptr.start()
|
||||||
ptr.tick(1000000) # wait a long time
|
ptr.ptr_tick(1000000) # wait a long time
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
if byte != 0377:
|
if byte != 0377:
|
||||||
print('Error')
|
print('Error')
|
||||||
ptr.tick(1000000) # wait a long time
|
ptr.ptr_tick(1000000) # wait a long time
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
if byte != 0377:
|
if byte != 0377:
|
||||||
print('Error')
|
print('Error')
|
||||||
ptr.stop()
|
ptr.stop()
|
||||||
|
ptr.ptr_dismount()
|
||||||
|
|
||||||
def create_papertape(filename):
|
def create_papertape(filename):
|
||||||
"""Create a PTP file."""
|
"""Create a PTP file."""
|
||||||
@@ -67,41 +76,38 @@ def create_papertape(filename):
|
|||||||
def create_papertape_ptp(ptp, filename):
|
def create_papertape_ptp(ptp, filename):
|
||||||
"""Create a PTP file using the Ptp device."""
|
"""Create a PTP file using the Ptp device."""
|
||||||
|
|
||||||
ptp.mount(filename)
|
# ptp.reset()
|
||||||
ptp.start()
|
ptp.ptp_mount(filename)
|
||||||
|
|
||||||
# leader
|
# leader
|
||||||
for _ in range(128):
|
for _ in range(128):
|
||||||
while not ptp.ready():
|
while not ptp.ready():
|
||||||
ptp.tick(1)
|
ptp.ptp_tick(1)
|
||||||
ptp.write(chr(0))
|
ptp.punch(chr(0))
|
||||||
while ptp.ready():
|
while ptp.ready():
|
||||||
ptp.tick(1)
|
ptp.ptp_tick(1)
|
||||||
|
|
||||||
# body
|
# body
|
||||||
for v in range(1, 256):
|
for v in range(1, 256):
|
||||||
while not ptp.ready():
|
while not ptp.ready():
|
||||||
ptp.tick(1)
|
ptp.ptp_tick(1)
|
||||||
ptp.write(chr(v))
|
ptp.punch(chr(v))
|
||||||
while ptp.ready():
|
|
||||||
ptp.tick(1)
|
|
||||||
|
|
||||||
# trailer
|
# trailer
|
||||||
for _ in range(128):
|
for _ in range(128):
|
||||||
while not ptp.ready():
|
while not ptp.ready():
|
||||||
ptp.tick(1)
|
ptp.ptp_tick(1)
|
||||||
ptp.write(chr(0))
|
ptp.punch(chr(0))
|
||||||
while ptp.ready():
|
|
||||||
ptp.tick(1)
|
|
||||||
|
|
||||||
ptp.stop()
|
# ptp.stop()
|
||||||
ptp.dismount()
|
ptp.ptp_dismount()
|
||||||
|
|
||||||
def read_tape(ptr, filename):
|
def read_tape(ptr, filename):
|
||||||
"""Create tape and read it."""
|
"""Create tape and read it."""
|
||||||
|
|
||||||
# now mount and read tape
|
# now mount and read tape
|
||||||
ptr.mount(filename)
|
# ptr.reset()
|
||||||
|
ptr.ptr_mount(filename)
|
||||||
ptr.start()
|
ptr.start()
|
||||||
|
|
||||||
# read leader
|
# read leader
|
||||||
@@ -109,10 +115,10 @@ def read_tape(ptr, filename):
|
|||||||
count = 0
|
count = 0
|
||||||
while True:
|
while True:
|
||||||
while not ptr.ready():
|
while not ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
while ptr.ready():
|
while ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
if byte != 0:
|
if byte != 0:
|
||||||
break
|
break
|
||||||
count += 1
|
count += 1
|
||||||
@@ -124,10 +130,10 @@ def read_tape(ptr, filename):
|
|||||||
count = 1
|
count = 1
|
||||||
while True:
|
while True:
|
||||||
while not ptr.ready():
|
while not ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
while ptr.ready():
|
while ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
if byte == 0:
|
if byte == 0:
|
||||||
break
|
break
|
||||||
count += 1
|
count += 1
|
||||||
@@ -139,29 +145,41 @@ def read_tape(ptr, filename):
|
|||||||
count = 1
|
count = 1
|
||||||
while True:
|
while True:
|
||||||
while not ptr.ready():
|
while not ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
byte = ptr.read()
|
byte = ptr.read()
|
||||||
if byte != 0:
|
if byte != 0:
|
||||||
break
|
break
|
||||||
count += 1
|
count += 1
|
||||||
while ptr.ready():
|
while ptr.ready():
|
||||||
ptr.tick(1)
|
ptr.ptr_tick(1)
|
||||||
|
|
||||||
ptr.stop()
|
ptr.stop()
|
||||||
|
|
||||||
print('%d bytes of trailer' % count)
|
print('%d bytes of trailer' % count)
|
||||||
|
|
||||||
|
ptr.ptr_dismount()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Test the papertape reader."""
|
"""Test the papertape reader."""
|
||||||
|
|
||||||
ptr = Ptr.Ptr()
|
try:
|
||||||
ptp = Ptp.Ptp()
|
os.remove(Logfile)
|
||||||
|
except OSError:
|
||||||
|
pass # ignore 'file not there'
|
||||||
|
|
||||||
read_no_tape(ptr)
|
ptrptp = PtrPtp.PtrPtp()
|
||||||
|
logger('created reader/punch device')
|
||||||
|
|
||||||
|
read_no_tape(ptrptp)
|
||||||
|
logger('After read_no_tape')
|
||||||
create_papertape(PtrFilename)
|
create_papertape(PtrFilename)
|
||||||
read_tape(ptr, PtrFilename)
|
logger('After create_papertape')
|
||||||
create_papertape_ptp(ptp, PtpFilename)
|
read_tape(ptrptp, PtrFilename)
|
||||||
read_tape(ptr, PtpFilename)
|
logger('After read_tape')
|
||||||
|
create_papertape_ptp(ptrptp, PtpFilename)
|
||||||
|
logger('After create_papertape_ptp')
|
||||||
|
read_tape(ptrptp, PtpFilename)
|
||||||
|
logger('After read_tape')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user