Home:ALL Converter>FTDI RS485 to USB adapter trying to read port as binary using Rasp PI and Python

FTDI RS485 to USB adapter trying to read port as binary using Rasp PI and Python

Ask Time:2021-02-04T05:11:01         Author:ItCompliedSoItMustBeGood

Json Formatter

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.

Author:ItCompliedSoItMustBeGood,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66035723/ftdi-rs485-to-usb-adapter-trying-to-read-port-as-binary-using-rasp-pi-and-python
yy