BirchJD / PiOBDII

ODBII graphic interface on a Raspberry Pi computer, using an ELM327 Bluetooth/USB device. Read and display engine data, OBDII Trouble Codes & Descriptions Using Python. YouTube video: https://www.youtube.com/watch?v=yTRAhubZhsU
263 stars 71 forks source link

strange output after connection #7

Open whoAmI-cslim opened 4 years ago

whoAmI-cslim commented 4 years ago

First and foremost, absolutely love this project! I am able to successfully connect to my ODBII bluetooth adapter.

When I initiate your software, it loads and states that is connecting to the CAN BUS; however, it never connects. When i close the software, there are the following errors in the terminal:

"invalid literal for int() with base 16: 'CH' "

I'm not that great with Python otherwise I'd inspect the code myself. Is this a quick fix item?

whoAmI-cslim commented 4 years ago

Also, I wanted to add that it may be occurring with PID 0101. When looking in ELM327.py, there's a string of coding for PID 0101. This was displayed in the terminal before the error.

I could only find a few integer references to possible base 16 when reviewing the ELM327.py.

Unfortunately, as stated before, this is well beyond my expertise, lol.

Perhaps the following code is causing the issue??:

    ResultVal1 = int(Response[:2], 16)
        if (ResultVal1 & 0x80) != 0:
            self.MilOn = True
            ResultArray += ("MIL:ON",)
        else:
            self.MilOn = False
            ResultArray += ("MIL:OFF",)
        self.FreezeFrameCount = ResultVal1 & 0x7F
        ResultArray += ("STORED TROUBLE CODE COUNT|" + str(self.FreezeFrameCount),)

        ResultVal1 = int(Response[2:4], 16)
whoAmI-cslim commented 4 years ago

I’ll post a debug readout shortly

EddieRadarHughes commented 4 years ago

I had the same exact issue and error message as WhoAmI-cslim. I have tried this code with two different OBD II scanners with two separate vehicles (Kia and Jeep) and I get this same error. I did not see a resolution posted here or on any other site. I was able to find one -- see below.

Note that I can use a terminal program like screen and send any of the AT commands (like atz, or atsp0, or 010C) and get back a valid response. So I knew the issue was internal to this program. The response to 0101 (which is when the program fails) is 41010007E500 followed by 410100040000. Line 396 of the module ELM327.py is the issue. This line is trying to invoke int(Response[:2], 16), which causes the error that prevents the program from completing the connection process. Above the section of code you have listed above, there is a call to self.PruneData. That routine basically removes the first 5 characters of each of the two lines and then combines those lines. So the result should have been to create 0007E50000040000 (striking 4101 from each line and then combine them as a single string). However, both of my devices issue the command "SEARCHING...". So the PruneData return value is Response = "CHING...0007E50000040000." This results in an error since Response has an invalid Hex value.

I changed EM327.py by adding the following before line 396 (ResultVal1=int(Response[:2],16)): if (Response[:8]=="CHING...": Response=Response[9:]

I saved an rerun the program. It now successfully completes that process.

Maximus5940 commented 1 year ago

Hello EddieRadarHughes, I'm currently getting this project started, and I have the same error as you two, I see your solution but I don't understand where exactly to place it, I see it's line 396 (ResultVal1 =int(Response[:2],16)): but there are other things in it, should it be deleted and replaced? Or just put it in with the rest?

J'ai eu exactement le même problème et le même message d'erreur que WhoAmI-cslim. J'ai essayé ce code avec deux scanners OBD II différents avec deux véhicules distincts (Kia et Jeep) et j'obtiens la même erreur. Je n'ai pas vu de résolution publiée ici ou sur un autre site. J'ai pu en trouver un - voir ci-dessous.

Notez que je peux utiliser un programme de terminal comme screen et envoyer n'importe laquelle des commandes AT (comme atz, atsp0 ou 010C) et obtenir une réponse valide. Je savais donc que le problème était interne à ce programme. La réponse à 0101 (lorsque le programme a échoué) est 41010007E500 suivi de 410100040000. La ligne 396 du module ELM327.py est le problème. Cette ligne tente d'invoquer int(Response[:2], 16), ce qui provoque l'erreur qui empêche le programme de terminer le processus de connexion. Au-dessus de la section de code que vous avez répertoriée ci-dessus, il y a un appel à self.PruneData. Cette routine supprime essentiellement les 5 premiers caractères de chacune des deux lignes, puis combine ces lignes.Le résultat aurait donc dû être de créer 0007E50000040000 (en supprimant 4101 de chaque ligne, puis en les combinant en une seule chaîne). Cependant, mes deux appareils lancent la commande "RECHERCHE...". Ainsi, la valeur de retour PruneData est Response = "CHING...0007E50000040000." Cela entraîne une erreur car la réponse a une valeur hexadécimale non valide.

J'ai changé EM327.py en ajoutant ce qui suit avant la ligne 396 (ResultVal1=int(Response[:2],16)): if (Response[:8]=="CHING...": Response=Response [9 :]

J'ai enregistré une réexécution du programme. Il termine maintenant avec succès ce processus.

Maximus5940 commented 1 year ago

else: Response = self.PruneData(Response, 2) ResultVal1 = int(Response[:2], 16) if (ResultVal1 & 0x80) != 0: self.MilOn = True self.FreezeFrameCount = ResultVal1 & 0x7F``

Maximus5940 commented 1 year ago

@EddieRadarHughes This is the code, could you let me know what you did to make it work please?

Maximus5940 commented 1 year ago

else: Response = self.PruneData(Response, 2) if (Response[:8]=="CHING...": Response=Response [9 :] ResultVal1 = int(Response[:2], 16) if (ResultVal1 & 0x80) != 0: ____self.MilOn = True __self.FreezeFrameCount = ResultVal1 & 0x7F

is this so? I understood after that it was before line 396 lol but is the indentation good?