I'm new to python and am having trouble figuring out how to read a serial port out as Hex or binary. I have a FTDI RS485 to USB device that shows up as a virtual serial port on USB0. I found enough information to make the below code that reads out the serial data but it's showing up as characters and symbols and I haven't figured out how to output it as hex or binary instead so I can read the data.
import serial, sys
port = '/dev/ttyUSB0'
baudrate = 9600
ser = serial.Serial(port,baudrate,timeout=0.01)
while True
data = ser.read(1)
data+= ser.read(ser.inWaiting())
sys.stdout.write(data)
sys.stdout.flush()
As a full project overview, this is the first part of a larger goal to setup my raspPi to act as a datalogger on a RS485 network. I have a few RS485 devices networked that I believe are randomly missing messages but they don't have datalogging built in to confirm what is actually happening so my goal is to make one I can setup and leave for a week.