01234567890123456789012345678901234567890123456789012345678901234567890123456789
288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 | <----SKIPPED LINES----> if not format_string: format_string = self.read_format try: data = Read(self.link, format_string, bytes_read=bytes_read) except OSError as e: failure_message = 'Failed to read: %s' % e if self.error_pin: self.to_parent_q.put(('pin', (self.error_pin, True, failure_message))) self.Reopen(log_message=failure_message) return self.Read(format_string=format_string) self.last_read = time.time() if data: self.last_receipt = time.time() if LOG_SERIALS: ts = time.time() - self.start_time str_data = str(['%7.2f' % d if isinstance(d, float) else str(d) for d in data]) with open(SERIALS_LOG, 'a') as f: f.write('%10.3f RECD@%s: %s\n' % (ts, self.name, str_data)) if self.read_timeout and self.last_read - self.last_receipt > self.read_timeout: failure_message = 'Heartbeat not received in %.2f seconds (expected: %.2f)' % ( self.last_read - self.last_receipt, self.read_timeout) if self.error_pin: self.to_parent_q.put(('pin', (self.error_pin, True, failure_message))) self.Reopen(log_message=failure_message) return self.Read(format_string=format_string) return data def Write(self, values, format_string=None): """Writes to an open serial. Writes to an open serial values as identified in the format_string provided here, or if not provided in this call, as saved on the Serial instance. If an OSError exception is detected, this method will attempt to reopen the connection. Args: values: tuple of values to send matching that as identified in format_string. format_string: String of the form expected by struct.pack """ ts = time.time() - self.start_time str_values = str(['%7.2f' % v if isinstance(v, float) else str(v) for v in values]) <----SKIPPED LINES----> |
01234567890123456789012345678901234567890123456789012345678901234567890123456789
288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 | <----SKIPPED LINES----> if not format_string: format_string = self.read_format try: data = Read(self.link, format_string, bytes_read=bytes_read) except OSError as e: failure_message = 'Failed to read: %s' % e if self.error_pin: self.to_parent_q.put(('pin', (self.error_pin, True, failure_message))) self.Reopen(log_message=failure_message) return self.Read(format_string=format_string) self.last_read = time.time() if data: self.last_receipt = time.time() if LOG_SERIALS: ts = time.time() - self.start_time str_data = str(['%7.2f' % d if isinstance(d, float) else str(d) for d in data]) with open(SERIALS_LOG, 'a') as f: f.write('%10.3f RECD@%s: %s\n' % (ts, self.name, str_data)) if self.read_timeout and self.last_read - self.last_receipt > self.read_timeout: failure_message = 'Heartbeat not received in %.2f seconds (expected: %.2f) on %s' % ( self.last_read - self.last_receipt, self.read_timeout, self.name) if self.error_pin: self.to_parent_q.put(('pin', (self.error_pin, True, failure_message))) self.Reopen(log_message=failure_message) return self.Read(format_string=format_string) return data def Write(self, values, format_string=None): """Writes to an open serial. Writes to an open serial values as identified in the format_string provided here, or if not provided in this call, as saved on the Serial instance. If an OSError exception is detected, this method will attempt to reopen the connection. Args: values: tuple of values to send matching that as identified in format_string. format_string: String of the form expected by struct.pack """ ts = time.time() - self.start_time str_values = str(['%7.2f' % v if isinstance(v, float) else str(v) for v in values]) <----SKIPPED LINES----> |