Moacir Ferreira
Moacir Ferreira

Reputation: 51

Python serial to bytes fails when passing array

First, I am a beginner... My code is:

data = bytearray(b'\x01\x04\x00\x16\x00\x02\x00\xf9')

# 1 - does not work as expected:
ser.write(serial.to_bytes(data))
    
# 2 - works as expected:
ser.write(serial.to_bytes([0x01,0x04,0x00,0x16,0x00,0x02,0x90,0x0f]))

So, what am I missing? I need to have the same results as in 2 but loading the data from a bytearray.

Upvotes: 1

Views: 336

Answers (1)

Moacir Ferreira
Moacir Ferreira

Reputation: 51

Reading my own post I found the answer: The last two bytes are flipped.

Upvotes: 1

Related Questions