Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Limiter inverter with RS485 load setting
#25
OK, when they said "all items from Soyosource are not available now as they don't work now" they meant the factory was temporarily closed  Big Grin

They resumed operations today.

Also sharing my code, I hope it helps!
Code:
import struct
import time
import serial

ser_in  = serial.Serial('/dev/ttyUSB0',4800)
ser_out = serial.Serial('/dev/ttyUSB1',4800)

def computeCRC(power):
    pu = power >> 8
    pl = power & 0xFF
    return (264 - pu - pl) & 0xFF

def read_consumed_power(ser):
    time.sleep(0.1) # Wait and clear input buffer to ensure proper packet synchronization
    ser.reset_input_buffer()
    try:
        raw = ser.read(8) # Read 8 bytes
    except: return -1
   
    (a,b,divider,c,consumed_power,d,crc) = struct.unpack('>BBBBHBB', raw)
    if computeCRC(consumed_power) != crc: return -2 # Checksum mismatch
   
    return consumed_power

def set_generated_power(ser, power):
    a = 0x24
    b = 0x56
    divider = 0x00
    c = 0x21
    d = 0x80
   
    crc = computeCRC(power)
    out = struct.pack('>BBBBHBB', a,b,divider,c,power,d,crc)
    ser.write(out)
    ser.flush() # Wait for data to be written out

while True:
    consumed_power = read_consumed_power(ser_in)
    if consumed_power < 0: continue
    print(consumed_power)
   
    desired_power = consumed_power + 6 # Add 6 extra watts, for example to compensate and completely null out the utility meter
   
    set_generated_power(ser_out, desired_power)

ser_in.close()
ser_out.close()
completelycharged likes this post
Reply


Messages In This Thread
RE: Limiter inverter with RS485 load setting - by CarlosGS - 03-04-2020, 10:30 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)