I have this code:
def checksum_calc(data):
checksum = 0
for ch in data:
checksum += ord(ch)
return hex(checksum % 256)
checksum=checksum_calc('\xAA\x41\xA1\x0E\x63\x02\x15\x0A\x3F\x00\x00\x00\x00')
test=[0xAA,0x41,0xA1,0x0E,0x63,0x02,0x15,0x0A,0x3F,0x00,0x00,0x00,0x00,checksum]
ser.write(serial.to_bytes(test))
the data that I need to send in serial is variable and can be changed based on other parts of my code, so I need to calculate the checksum of data and then send it by using serial.to_bytes
when I run the code it returns: string must be of size 1
however checksum_calc function works well but I can not put the result of that in test variable and send it to serial.
how can I put checksum result in the test variable?