def __init__(self, arg, max_reclen, serial_in_size): """ Initialise COMn: device. """ devices.Device.__init__(self) addr, val = devices.parse_protocol_string(arg) self.stream = None try: if not addr and not val: pass elif addr == 'SOCKET': self.stream = SocketSerialStream(val) elif addr == 'STDIO' or (not addr and val.upper() == 'STDIO'): crlf = (val.upper() == 'CRLF') self.stream = StdIOStream(crlf) elif addr == 'PORT': # port can be e.g. /dev/ttyS1 on Linux or COM1 on Windows. self.stream = SerialStream(val) else: logging.warning('Could not attach %s to COM device', arg) except (ValueError, EnvironmentError) as e: logging.warning('Could not attach %s to COM device: %s', arg, e) self.stream = None except AttributeError: logging.warning('Serial module not available. Could not attach %s to COM device: %s.', arg, e) self.stream = None if self.stream: # NOTE: opening a text file automatically tries to read a byte self.device_file = COMFile(self.stream, linefeed=False)
def __init__(self, arg): """ Initialise tape device. """ addr, val = devices.parse_protocol_string(arg) valsplit = val.split(':', 1) loc = None if len(valsplit) == 2: val, loc = valsplit ext = val.split('.')[-1].upper() # we use a dummy device_file # this means WIDTH and LOC on CAS1: directly are ignored self.device_file = DummyDeviceFile() try: if not val: self.tapestream = None elif addr == 'BC': self.tapestream = BasicodeStream(BasicodeWAVBitStream(val, 'r')) elif addr == 'WAV' or (addr != 'CAS' and ext == 'WAV'): # if unspecified, determine type on the basis of filename extension self.tapestream = CassetteStream(WAVBitStream(val, 'r')) else: # 'CAS' is default self.tapestream = CassetteStream(CASBitStream(val, 'r')) if loc: self.tapestream.wind(int(loc)) except EnvironmentError as e: logging.warning("Couldn't attach %s to CAS device: %s", val, str(e)) self.tapestream = None
def __init__(self, arg, default_stream, flush_trigger): """ Initialise LPTn: device. """ devices.Device.__init__(self) addr, val = devices.parse_protocol_string(arg) self.stream = default_stream if addr == 'FILE': try: if not os.path.exists(val): open(val, 'wb').close() self.stream = open(val, 'r+b') except (IOError, OSError) as e: logging.warning('Could not attach file %s to LPT device: %s', val, str(e)) elif addr == 'PARPORT': # port can be e.g. /dev/parport0 on Linux or LPT1 on Windows. Just a number counting from 0 would also work. self.stream = parallel_port(val) elif addr == 'STDIO' or (not addr and val == 'STDIO'): crlf = (val.upper() == 'CRLF') self.stream = StdIOStream(crlf) elif addr == 'PRINTER' or not addr: # 'PRINTER' is default self.stream = printer.PrinterStream(val) else: logging.warning('Could not attach %s to LPT device', arg) if self.stream: self.device_file = LPTFile(self.stream, flush_trigger) self.device_file.flush_trigger = flush_trigger
def __init__(self, arg): """ Initialise tape device. """ addr, val = devices.parse_protocol_string(arg) valsplit = val.split(':', 1) loc = None if len(valsplit) == 2: val, loc = valsplit ext = val.split('.')[-1].upper() # we use a dummy device_file # this means WIDTH and LOC on CAS1: directly are ignored self.device_file = DummyDeviceFile() try: if not val: self.tapestream = None elif addr == 'BC': self.tapestream = BasicodeStream(BasicodeWAVBitStream( val, 'r')) elif addr == 'WAV' or (addr != 'CAS' and ext == 'WAV'): # if unspecified, determine type on the basis of filename extension self.tapestream = CassetteStream(WAVBitStream(val, 'r')) else: # 'CAS' is default self.tapestream = CassetteStream(CASBitStream(val, 'r')) if loc: self.tapestream.wind(int(loc)) except EnvironmentError as e: logging.warning("Couldn't attach %s to CAS device: %s", val, str(e)) self.tapestream = None