'Python Serial Read 3 byte hex and print as an array on one line
I have a simple program that is receiving hex data via serial port it is in 6 bytes. When I print it out it prints on separate lines.
import serial
ser = serial.Serial('COM15')
print(ser.name)
while True:
in_hex = ser.read().hex()
print(in_hex)
Output:
aa
40
16
44
00
56
How can I make this on one line ? For Example {aa, 40 16, aa, 00, 56} I have tried bytearray, tried setting array size. Everything I try does not work.
Can I set the string length somehow?
After This I want to verify the first element. if that is true then verify the following elements match. any suggestions would be great Thank You
Solution 1:[1]
Make in_hex into an array and append each element to the array.
Then you can print in_hex and it will print all the numbers on the same line, as you intended.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Landon |