Esempio n. 1
0
 def get_pid(pid='00'):
     try:
         self._process_pid(mode, pid)
     except Exception as err:
         # logging
         logger.error(err)
     return self
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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()
Esempio n. 5
0
    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
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 def check_connection(self):
     if not self.__connected:
         mess = "Failed connection to the OBD2 interface!"
         logger.error(mess)
         raise Exception(mess)