Index: leahi_dialin/dd/modules/records.py =================================================================== diff -u -r6d9a45c779b9ee3c362f85820db9f89d8dbb8b3c -ree914de19a46c34d2103b56072640895779728ec --- leahi_dialin/dd/modules/records.py (.../records.py) (revision 6d9a45c779b9ee3c362f85820db9f89d8dbb8b3c) +++ leahi_dialin/dd/modules/records.py (.../records.py) (revision ee914de19a46c34d2103b56072640895779728ec) @@ -27,7 +27,7 @@ from leahi_dialin.utils.abstract_classes import AbstractSubSystem from leahi_dialin.utils.base import publish from leahi_dialin.utils.enums import DialinEnum -from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray, byte_to_bytearray, unsigned_short_to_bytearray +from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray, byte_to_bytearray, unsigned_short_to_bytearray, string_to_bytearray class DDRecords(AbstractSubSystem): @@ -576,11 +576,9 @@ raise ValueError(f'serial must be 20 characters, provided is: {len(serial_number)}') payload = integer_to_bytearray(is_ro_featured) - payload = integer_to_bytearray(is_ro_featured_boost_pump) - for c in part_number: - payload += byte_to_bytearray(c) - for c in serial_number: - payload += byte_to_bytearray(c) + payload += integer_to_bytearray(is_ro_featured_boost_pump) + payload += string_to_bytearray(part_number) + payload += string_to_bytearray(serial_number) payload += integer_to_bytearray(manufacturing_location) payload += integer_to_bytearray(manufacturing_date) payload += unsigned_short_to_bytearray(self.crc16(payload)) Index: leahi_dialin/utils/conversions.py =================================================================== diff -u -r6a318bab36cd1e28b42a0683abd5052b63ed5f20 -ree914de19a46c34d2103b56072640895779728ec --- leahi_dialin/utils/conversions.py (.../conversions.py) (revision 6a318bab36cd1e28b42a0683abd5052b63ed5f20) +++ leahi_dialin/utils/conversions.py (.../conversions.py) (revision ee914de19a46c34d2103b56072640895779728ec) @@ -19,6 +19,16 @@ # https://docs.python.org/3/library/struct.html#format-characters +def string_to_bytearray(val: str) -> bytes: + """ + Converts a string value into a byte array (little endian) + + @param val: (str) string to convert to byte array + @return: byte array + """ + return struct.pack(f"{len(val)}s", val.encode('ascii')) + + def byte_to_bytearray(val: int) -> bytes: """ Converts a byte value into a byte array (little endian)