Aug-11-2021, 01:50 PM
Hello,
I want to make the following :
today I'm reading canbus data in this form (the data is string type)
so in the end I will have this :
Data_List[3] --> 'a2'
the reason in to make an easy list and not to think how to get to item 3 (places 9 and 10)
so insted of writing
Data[9:11] I will wirte Data_List[3]
hope the reason is clear
I mange to to this:
Thanks ,
I want to make the following :
today I'm reading canbus data in this form (the data is string type)
Data = d8 59 80 a2 c8 be f4 92I want to make a function the take the data, put every 2 digits into 1 place in a list
so in the end I will have this :
Data_List = [d8, 59, 80, a2, c8, be, f4, 92]then I will create a function that will print the data for place 0-7 according to input
Data_List[3] --> 'a2'
the reason in to make an easy list and not to think how to get to item 3 (places 9 and 10)
so insted of writing
Data[9:11] I will wirte Data_List[3]
hope the reason is clear
I mange to to this:
def CutData(FullData, StartByte, length=1): Byte_Data = [] print(f'full data is {FullData}') print(f'size is {len(FullData)}') i = 0 test = "" for Char in FullData: print(str(i) + " : " + Char ) if Char != " ": test = test + Char Byte_Data.insert(i, test) i += 1 else: test = "" print(Byte_Data) Byte_Data = Byte_Data[1::2] print(Byte_Data)which retunr this:
full data is d8 59 80 a2 c8 be f4 92 size is 23 0 : d 1 : 8 2 : 2 : 5 3 : 9 4 : 4 : 8 5 : 0 6 : 6 : a 7 : 2 8 : 8 : c 9 : 8 10 : 10 : b 11 : e 12 : 12 : f 13 : 4 14 : 14 : 9 15 : 2 ['d', 'd8', '5', '59', '8', '80', 'a', 'a2', 'c', 'c8', 'b', 'be', 'f', 'f4', '9', '92'] ['d8', '59', '80', 'a2', 'c8', 'be', 'f4', '92']I guess this is OK - but is there more "normal" \ pretty way to do this?
Thanks ,