139 lines
3.5 KiB
Python
Executable file
139 lines
3.5 KiB
Python
Executable file
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
import time
|
|
import serial, sys
|
|
import os
|
|
from datetime import datetime
|
|
from bitstring import BitArray
|
|
|
|
|
|
serial_timeout=0.1
|
|
byte3=0
|
|
byte4=0
|
|
byte5=0
|
|
byte6=0
|
|
i=0
|
|
|
|
pvfaultdesc = [0]*8
|
|
pvfaultdesc[0]="load short-circuit protection"
|
|
pvfaultdesc[1]="load overcurrent protection"
|
|
pvfaultdesc[2]="battery low-voltage protection"
|
|
pvfaultdesc[3]="reserved"
|
|
pvfaultdesc[4]="solar panel array1 open-circuit breakdown(it means the controller does not detect the solar panel voltage within 24h)"
|
|
pvfaultdesc[5]="solar panel array1 over-voltage protection"
|
|
pvfaultdesc[6]="delayed protection phase for load overcurrent"
|
|
pvfaultdesc[7]="shut the load compulsively"
|
|
|
|
|
|
|
|
|
|
def pv_reset_lowvoltage():
|
|
print("Reset Unterspannungs Sicherung:")
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=serial_timeout)
|
|
command = "\x01\x51\x00\x00\x00\x00\x39"
|
|
global byte3
|
|
global byte4
|
|
ser.flushInput() #clear buffer
|
|
ser.write(command) #send prepared command
|
|
ser.close()
|
|
print("DONE")
|
|
|
|
|
|
|
|
def pv_reset_shortcuircuit():
|
|
print("Reset Kurzschluss Sicherung:")
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=serial_timeout)
|
|
command = "\x01\x53\x00\x00\x00\x00\xAE"
|
|
global byte3
|
|
global byte4
|
|
ser.flushInput() #clear buffer
|
|
ser.write(command) #send prepared command
|
|
ser.close()
|
|
print("DONE")
|
|
|
|
def pv_reset_overcurrent():
|
|
print("Reset Ueberlast Sicherung:")
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=serial_timeout)
|
|
command = "\x01\x52\x00\x00\x00\x00\x7D"
|
|
global byte3
|
|
global byte4
|
|
ser.flushInput() #clear buffer
|
|
ser.write(command) #send prepared command
|
|
ser.close()
|
|
print("DONE")
|
|
|
|
|
|
|
|
def pvstatusbit(bit):
|
|
if bit == '1':
|
|
print("gesetzt :%s" % bit)
|
|
else:
|
|
print("nicht gesetzt :%s" % bit)
|
|
|
|
def pvstatus():
|
|
# current status of system
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=serial_timeout)
|
|
command = "\x01\x61\x00\x00\x00\x00\xBD"
|
|
global byte3
|
|
global byte4
|
|
ser.flushInput() #clear buffer
|
|
ser.write(command) #send prepared command
|
|
skip=ser.read(2) #skip first two bytes
|
|
byte3=ser.read(1)
|
|
byte4=ser.read(1)
|
|
ser.close()
|
|
|
|
if (
|
|
len(byte3) > 0 and len(byte4) > 0
|
|
):
|
|
byte3=byte3.encode('hex')
|
|
bitstring1=BitArray(hex=byte3)
|
|
# sys.stdout.write('Inputstring:\t')
|
|
# sys.stdout.write(bitstring1.bin)
|
|
# sys.stdout.write('\n')
|
|
pvfaultstate(bitstring1.bin)
|
|
sys.stdout.write('\n')
|
|
else :
|
|
sys.stdout.write('Voltage communication error!')
|
|
|
|
def pvfaultstate(bytearray):
|
|
global pvfaultdesc
|
|
# print("Inputstring Funktion:\t %s" %bytearray)
|
|
i=0
|
|
arraylen=len(bytearray)
|
|
# print (" Array ist %s Elemente lang" %(arraylen))
|
|
while i <=arraylen-1:
|
|
if bytearray[i] =='1':
|
|
print("Fehler aktiv: %s (Byte: %s)" % (pvfaultdesc[i], i) )
|
|
#pvstatusbit(bytearray[i])
|
|
if i<=arraylen: i=i+1
|
|
|
|
|
|
|
|
while True:
|
|
try:
|
|
now = datetime.now()
|
|
|
|
os.system('clear')
|
|
print(now)
|
|
print("aktive Fehler:")
|
|
pvstatus()
|
|
time.sleep(0.5)
|
|
#pv_reset_shortcuircuit()
|
|
#time.sleep(0.5)
|
|
pv_reset_overcurrent()
|
|
time.sleep(0.5)
|
|
pv_reset_lowvoltage()
|
|
print("aktive Fehler nach reset:")
|
|
pvstatus()
|
|
print("erneuter reset nach 5 Sekunden")
|
|
# sleep 10 seconds before starting over
|
|
time.sleep(5)
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n\nkilled via CTRL+C - Bye")
|
|
#pvswitch(0) #last ausschalten
|
|
|
|
|
|
sys.exit()
|