def print_and_debug(self): self.continue_reading(0.2) instructions = chunker(self.instructions_data) instructions = merge_specific_instructions(instructions, join_preamble=True, join_raster=self.merge_specific_instructions) for instruction in instructions: opcode = match_opcode(instruction) opcode_def = OPCODES[opcode] cmd_name = opcode_def[0] hex_instruction = hex_format(instruction).split() if len(hex_instruction) > 100: hex_instruction = ' '.join(hex_instruction[0:70] + ['[...]'] + hex_instruction[-30:]) else: hex_instruction = ' '.join(hex_instruction) logger.info("CMD {} FOUND. Instruction: {} ".format(cmd_name, hex_instruction)) if self.interactive: input('Continue?') # WRITE self.be.write(instruction) # SLEEP BEFORE READ time.sleep(self.sleep_before_read) # READ response = self.be.read() #response += self.be.read() if response != b'': logger.info("Response from the device: {}".format(hex_format(response))) self.log_interp_response(response) # SLEEP BETWEEN INSTRUCTIONS time.sleep(self.sleep_time) self.continue_reading(self.continue_reading_for)
def __init__(self, dev, instructions_data, backend='linux_kernel'): be_cls = backend_factory(backend)['backend_class'] self.be = be_cls(dev) self.sleep_time = 0.0 self.sleep_before_read = 0.0 self.continue_reading_for = 3.0 self.start = time.time() self.interactive = False self.merge_specific_instructions = True if type(instructions_data) in (str, ): with open(instructions_data, 'rb') as f: self.instructions_data = f.read() elif type(instructions_data) in (bytes, ): self.instructions_data = instructions_data else: raise NotImplementedError( 'Only filename or bytes supported for instructions_data argument' ) response = self.be.read() if response: logger.warning( 'Received response before sending instructions: {}'.format( hex_format(response)))
def log_interp_response(self, data): try: interp_result = interpret_response(data) logger.info( "Interpretation of the response: '{status_type}' (phase: {phase_type}), '{media_type}' {media_width}x{media_length} mm^2, errors: {errors}" .format(**interp_result)) except: logger.error("Couln't interpret response: %s", hex_format(data))
def print_and_debug(self): self.continue_reading(0.2) instructions = chunker(self.instructions_data) instructions = merge_specific_instructions( instructions, join_preamble=True, join_raster=self.merge_specific_instructions) for instruction in instructions: opcode = match_opcode(instruction) opcode_def = OPCODES[opcode] cmd_name = opcode_def[0] hex_instruction = hex_format(instruction).split() if len(hex_instruction) > 100: hex_instruction = ' '.join(hex_instruction[0:70] + ['[...]'] + hex_instruction[-30:]) else: hex_instruction = ' '.join(hex_instruction) logger.info("CMD {} FOUND. Instruction: {} ".format( cmd_name, hex_instruction)) if self.interactive: input('Continue?') # WRITE self.be.write(instruction) # SLEEP BEFORE READ time.sleep(self.sleep_before_read) # READ response = self.be.read() #response += self.be.read() if response != b'': logger.info("Response from the device: {}".format( hex_format(response))) self.log_interp_response(response) # SLEEP BETWEEN INSTRUCTIONS time.sleep(self.sleep_time) self.continue_reading(self.continue_reading_for)
def log_interp_response(self, data): try: interp_result = interpret_response(data) logger.info("Interpretation of the response: '{status_type}' (phase: {phase_type}), '{media_type}' {media_width}x{media_length} mm^2, errors: {errors}".format(**interp_result)) except: logger.error("Couln't interpret response: %s", hex_format(data))
def __init__(self, dev, instructions_data, backend='linux_kernel'): be_cls = backend_factory(backend)['backend_class'] self.be = be_cls(dev) self.sleep_time = 0.0 self.sleep_before_read = 0.0 self.continue_reading_for = 3.0 self.start = time.time() self.interactive = False self.merge_specific_instructions = True if type(instructions_data) in (str,): with open(instructions_data, 'rb') as f: self.instructions_data = f.read() elif type(instructions_data) in (bytes,): self.instructions_data = instructions_data else: raise NotImplementedError('Only filename or bytes supported for instructions_data argument') response = self.be.read() if response: logger.warning('Received response before sending instructions: {}'.format(hex_format(response)))