@@ -581,8 +581,9 @@ def __init__(self, portName, rate, adapter_type="STD", maxspeed="No"):
581581 os .mkdir ("./logs" )
582582
583583 if len (options .log ) > 0 :
584- self .lf = open ("./logs/elm_" + options .log , "at" )
585- self .vf = open ("./logs/ecu_" + options .log , "at" )
584+ self .lf = open ("./logs/elm_" + options .log + ".txt" , "at" , encoding = "utf-8" )
585+ self .vf = open ("./logs/ecu_" + options .log + ".txt" , "at" , encoding = "utf-8" )
586+ self .vf .write ("Timestamp;ECU_CAN_Address_HEX;Raw_Command_HEX;Raw_Response_HEX_or_STR;Error_message_if_happens\n " )
586587
587588 self .lastCMDtime = 0
588589 self .ATCFC0 = options .opt_cfc0
@@ -624,7 +625,7 @@ def __init__(self, portName, rate, adapter_type="STD", maxspeed="No"):
624625
625626 def raise_odb_speed (self , baudrate ):
626627 # Software speed switch
627- res = self .port .write (("ST SBR " + str (baudrate ) + "\r " ).encode ('utf8 ' ))
628+ res = self .port .write (("ST SBR " + str (baudrate ) + "\r " ).encode ('utf-8 ' ))
628629
629630 # Command echo
630631 res = self .port .expect_carriage_return ()
@@ -646,13 +647,13 @@ def raise_odb_speed(self, baudrate):
646647 def raise_elm_speed (self , baudrate ):
647648 # Software speed switch to 115Kbps
648649 if baudrate == 57600 :
649- res = self .port .write ("ATBRD 45\r " .encode ("utf8 " ))
650+ res = self .port .write ("ATBRD 45\r " .encode ("utf-8 " ))
650651 elif baudrate == 115200 :
651- res = self .port .write ("ATBRD 23\r " .encode ("utf8 " ))
652+ res = self .port .write ("ATBRD 23\r " .encode ("utf-8 " ))
652653 elif baudrate == 230400 :
653- res = self .port .write ("ATBRD 11\r " .encode ("utf8 " ))
654+ res = self .port .write ("ATBRD 11\r " .encode ("utf-8 " ))
654655 elif baudrate == 500000 :
655- res = self .port .write ("ATBRD 8\r " .encode ("utf8 " ))
656+ res = self .port .write ("ATBRD 8\r " .encode ("utf-8 " ))
656657 else :
657658 return
658659
@@ -665,7 +666,7 @@ def raise_elm_speed(self, baudrate):
665666 self .port .change_rate (baudrate )
666667 version = self .port .expect_carriage_return ()
667668 if "ELM327" in version :
668- self .port .write ('\r ' .encode ('utf8 ' ))
669+ self .port .write ('\r ' .encode ('utf-8 ' ))
669670 res = self .port .expect ('>' )
670671 if "OK" in res :
671672 print ("ELM full speed connection OK " )
@@ -681,7 +682,7 @@ def raise_elm_speed(self, baudrate):
681682 def __del__ (self ):
682683 try :
683684 print ("ELM reset..." )
684- self .port .write ("ATZ\r " .encode ("utf8 " ))
685+ self .port .write ("ATZ\r " .encode ("utf-8 " ))
685686 except :
686687 pass
687688
@@ -735,9 +736,9 @@ def request(self, req, positive='', cache=True, serviceDelay="0"):
735736 if self .vf != 0 :
736737 tmstr = datetime .now ().strftime ("%H:%M:%S.%f" )[:- 3 ]
737738 if self .currentaddress in dnat :
738- self .vf .write (tmstr + ";" + dnat [self .currentaddress ] + ";" + req + ";" + rsp + "\n " )
739+ self .vf .write (tmstr + ";" + "0x" + dnat [self .currentaddress ] + ";" + "0x" + req + ";" + "0x" + rsp . rstrip (). replace ( " " , ",0x" ) + ";" + "\n " )
739740 else :
740- print ("Unknown address " , self .currentaddress , req , rsp )
741+ print ("Unknown address: " , self .currentaddress , "0x" + req , "0x" + rsp )
741742 self .vf .flush ()
742743
743744 return rsp
@@ -912,7 +913,7 @@ def send_can(self, command):
912913 if self .vf != 0 :
913914 tmstr = datetime .now ().strftime ("%H:%M:%S.%f" )[:- 3 ]
914915 self .vf .write (
915- tmstr + ";" + dnat [self .currentaddress ] + ";" + command + ";" + result + ";" + errorstr + "\n " )
916+ tmstr + ";" + dnat [self .currentaddress ] + ";" + "0x" + command + ";" + result + ";" + errorstr + "\n " )
916917 self .vf .flush ()
917918
918919 # populate L1 cache
@@ -1193,7 +1194,7 @@ def monitor_can_bus(self, callback):
11931194 if options .simulation_mode :
11941195 pass
11951196 else :
1196- self .port .write ("AT MA\r " )
1197+ self .port .write ("AT MA\r " . encode ( 'utf-8' ) )
11971198 stream = ""
11981199 while not self .monitorstop :
11991200 byte = self .port .read ()
@@ -1211,7 +1212,7 @@ def monitor_can_bus(self, callback):
12111212 if byte :
12121213 stream += byte
12131214
1214- self .port .write ("AT\r " )
1215+ self .port .write ("AT\r " . encode ( 'utf-8' ) )
12151216 self .port .expect ('>' )
12161217
12171218 def init_can (self ):
0 commit comments