How can I read the data on a serial connection?

102 Views Asked by At

I have a serial connection to a solar inverter using a USB. Using a free serial device monitor I can spy on the connection and watch it read/write information.

The info my computer gets from the inverter can only be read and exported (to .xlsx) on their application. Their app has no automatic export functionality and no api. The end goal is to be able to export automatically without me touching the computer at designated time intervals. I'm trying to circumvent their app by reading the data myself, and saving it to .csv so I can do anything else that I want with it once I have it.

What the serial monitor shows, top is read, bottom is write

I can't seem to decode what its sending/recieving. And I also don't recieve anything when I send those same write messages. And when I'm just looping and trying to readline() I get empty bytes.

My code looks like this, though I have a few different iterations of it doing similar things like looping through every baudrate, stopbits, and bitsize option. As well as looping through the 5 different unique write messages I see in the monitor.

# Construct serial connection using baud and stopbit
serialPort = serial.Serial(port= "COM3", 
                                   baudrate=115200,
                                   bytesize=serial.EIGHTBITS,
                                   timeout=0,
                                   stopbits=serial.STOPBITS_ONE)
        
while(1):
    serialPort.write('01 03 00 2D 00 2D 15 DE'.encode()) 
    serialString = serialPort.readline()
    if serialString.decode() != '':
                print(serialString.decode())               

Any help or advice for what I'm doing is appreciated.

0

There are 0 best solutions below