def get_pid(pid='00'): try: self._process_pid(mode, pid) except Exception as err: # logging logger.error(err) return self
def connection(self, port, baudrate=DEFAULT_BAUDRATE): try: self.bus = uart_base(port, baudrate) self._mapping() except Exception as err: # logging exception logger.error(err) return None return self
def get_data(self, record): record = record[6:self.check_sum] if len(record) >= 6 and len(record) <= 16: # remove first 4 characters. This are service bytes from ELM # format mode:pid:data # ex: 4100FFFFFFFF - ELM spec page 38 record = record[4:] else: mess = "The frame size is not suitable." logger.error(mess) raise Exception(mess) return record
def receive(self): """ Receive data from connected OBD-II Scanner :return: the data returned by the OBD-II Scanner """ if self.is_port(): value = self.collect_data() if value: return Response(value, self.get_proto_num()) else: mess = "Cannot read when unconnected" logger.error(mess) raise Exception(mess) return Response()
def check_error(cls, data): """ Checks the error data. The data starts with 7F format: 7F mode code """ response = True codes = { 10: 'general reject', 11: 'service not supported', 12: 'invalid format', 21: 'busy', 22: 'conditions not correct', 78: 'pending replies' } if data[0][0:2] == '7F': # logging error logger.error('Error: mode {} - {}'.format(data[0][2:4], # mode codes.get(int(data[0][-2:]))) # code ) response = False return response
def check_echo_off(self): if not self._check_response(self.echo_off()): mess = "Echo command did not completed" logger.error(mess) raise Exception(mess)
def set_protocol(self): if not self._check_response( self.send(elm327.SET_PROTOCOL_AUTO_COMMAND).raw_value): mess = "Set protocol command did not completed" logger.error(mess) raise Exception(mess)
def header_on(self): if not self._check_response( self.send(elm327.HEADER_ON_COMMAND).raw_value): mess = "Enable header command did not completed" logger.error(mess) raise Exception(mess)
def check_connection(self): if not self.__connected: mess = "Failed connection to the OBD2 interface!" logger.error(mess) raise Exception(mess)