newbie bytes byte-arrays and uarts
Posted: Tue Feb 08, 2022 7:12 pm
Hi I'm very new to Python and wondering if there is a correct form passing data to a UART on pi Pico
I've found two different ways construct the payload via a byte-array and a sequence of bytes.
My question is do I have potential issues with either/both?
Many thanks in advance.
# byte-array
>>>modDataBA = bytearray(b'\x05\x03\x07\x00\x00\x00\x00\x0A')
>>>modDataBA.append(s0Dis)
>>>modDataBA.append(s0Dos)
>>>modDataBA: bytearray(b'\x05\x03\x07\x00\x00\x00\x00\n\x01\x01')
# byte-sequence
>>>modDataBY = b'\x05\x03\x07\x00\x00\x00\x00\x0A'+(s0Dis).to_bytes(1,'big')+(s0Dos).to_bytes(1,'big')
>>>modDataBY: <class 'bytes'> b'\x05\x03\x07\x00\x00\x00\x00\n\x01\x01'
I've found two different ways construct the payload via a byte-array and a sequence of bytes.
My question is do I have potential issues with either/both?
Many thanks in advance.
# byte-array
>>>modDataBA = bytearray(b'\x05\x03\x07\x00\x00\x00\x00\x0A')
>>>modDataBA.append(s0Dis)
>>>modDataBA.append(s0Dos)
>>>modDataBA: bytearray(b'\x05\x03\x07\x00\x00\x00\x00\n\x01\x01')
# byte-sequence
>>>modDataBY = b'\x05\x03\x07\x00\x00\x00\x00\x0A'+(s0Dis).to_bytes(1,'big')+(s0Dos).to_bytes(1,'big')
>>>modDataBY: <class 'bytes'> b'\x05\x03\x07\x00\x00\x00\x00\n\x01\x01'