CM5024Z Raspberry Pi rs-232 solar controller python script

I bought 50A PWM solar controller from ebay for power my shack. Controller have RS-232, so let’s it connect to raspi and read voltage!

File with protocol details and example:

CM30_COM

Device photo:

solar_controller

#!/usr/bin/python
import serial, sys
ser = serial.Serial('/dev/ttyUSB0', 9600)

command = "\x01\x10\x00\x00\x00\x00\x2B"

ser.open() # !!! in new version PySerial need comment
ser.flushInput() #clear buffer
ser.write(command) #send prepared command
#time.sleep(1) #maybe solve problems 
skip=ser.read(2) #skip first two bytes
byte3=ser.read(1)
byte4=ser.read(1)
ser.close()

value1=ord(byte3)
value2=ord(byte4)

voltage=(value2 * 256 + value1) / 100
voltage_modulo=(value2 * 256 + value1) % 100

#print(repr(byte3))
#print(repr(byte4))

sys.stdout.write(str(voltage))
sys.stdout.write('.')
sys.stdout.write(str(voltage_modulo)

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *