auslesen habe ich jetzt geschaft.
Code:
Code:
#!/usr./bin/python3 # -*- coding: utf-8 -*- import serial import time import sys StatusDict ={ 0: "Initphase", 1: "Warten auf Einspeisen", 2: "Generator-Spannung zu niedrig", 3: "Konstantspannungsregler", 4: "Einspeisebetrieb", 7: "Selbsttest in Arbeit", 8: "Selbsttest in Arbeit", 9: "Testbetrieb", 10: "Temperatur im Geraet zu hoch", 11: "Leistungsbegrenzung", 17: "Powador-protect Abschaltung", 18: "Fehlerstrom-Abschaltung (AIF)", 19: "Isolationsfehler Generator", 20: "Hochlaufbegrenzung aktiv", 29: "Erdschlusssicherung pruefen", 30: "Stoerung Messwandler", 31: "Fehler AFI-Modul", 32: "Fehler Selbsttest", 33: "Fehler DC-Einspeisung", 34: "Interner Kommunikationsfehler", 35: "Schutzabschaltung SW", 36: "Schutzabschaltung HW", 37: "Unbekannte Hardware", 38: "Fehler Generator-Ueberspannung", 41: "Netzstoerung Unterspannung L1", 42: "Netzstoerung Ueberspannung L1", 43: "Netzstoerung Unterspannung L2", 44: "Netzstoerung Ueberspannung L2", 45: "Netzstoerung Unterspannung L3", 46: "Netzstoerung Ueberspannung L3", 47: "Netzstoerung Aussenleiterspannung", 48: "Netzstoerung Unterfrequenz", 49: "Netzstoerung Ueberfrequenz", 50: "Netzstoerung Mittelwertspannung", 55: "Fehler Zwischenkreisspannung", 57: "Warten auf Wiederzuschalten", 58: "Uebertemperatur Steuerkarte", 59: "Fehler Selbsttest", 60: "Generator-Spannung zu hoch", 61: "Externe Begrenzung", 62: "Inselbetrieb", 63: "Frequenzabh. Leistungsreduzierung", 64: "Ausgangsstrombegrenzung", 65: "Fehler ROCOF", 67: "Fehler Leistungsteil 1", 68: "Fehler Leistungsteil 2", 69: "Fehler Leistungsteil 3", 70: "Fehler Luefter 1", 71: "Fehler Luefter 2", 72: "Fehler Luefter 3", 73: "Fehler Inselnetz", 74: "Externe Blindleistungsanforderung", 75: "Selbsttest in Arbeit", 78: "Fehlerstrom-Abschaltung (AFI)", 79: "Isolationsmessung", 80: "Isolationsmessung nicht moeglich", 81: "Schutzabschaltung Netzspg. L1", 82: "Schutzabschaltung Netzspg. L2", 83: "Schutzabschaltung Netzspg. L3", 84: "Schutzabschaltung Unterspg. ZK", 85: "Schutzabschaltung Ueberspg. ZK", 86: "Schutzabschaltung Unsymmetrie ZK", 87: "Schutzabschaltung Ueberstrom L1", 88: "Schutzabschaltung Ueberstrom L2", 89: "Schutzabschaltung Ueberstrom L3", 90: "Schutzabschaltung Einbruch 5V", 91: "Schutzabschaltung Einbruch 2.5V", 92: "Schutzabschaltung Einbruch 1.5V", 93: "Fehler Selbsttest Buffer 1", 94: "Fehler Selbsttest Buffer 2", 95: "Fehler Selbsttest Relais 1", 96: "Fehler Selbsttest Relais 2", 97: "Schutzabschaltung HW Ueberstrom", 98: "Schutzabschaltung HW Gate-Treiber", 99: "Schutzabschaltung HW Buffer-Freigabe", 100: "Schutzabschaltung HW Uebertemperatur", 101: "Plausibilitaetsfehler Temperatur", 102: "Plausibilitaetsfehler Wirkungsgrad", 103: "Plausibilitaetsfehler Zwischenkreis", 104: "Plausibilitaetsfehler AFI-Modul", 105: "Plausibilitaetsfehler Relais", 106: "Plausibilitaetsfehler DCDC-Wandler", 108: "Netzstoerung Ueberspannung L1", 109: "Netzstoerung Ueberspannung L2", 110: "Netzstoerung Ueberspannung L3", 111: "Netzstoerung Unterspannung L1", 112: "Netzstoerung Unterspannung L2", 113: "Netzstoerung Unterspannung L3", 114: "Kommunikationsfehler DC/DC", 115: "Negativer DC-Strom 1", 116: "Negativer DC-Strom 2", 117: "Negativer DC-Strom 3", 118: "DC-Ueberspannung 1", 119: "DC-Ueberspannung 2", 120: "DC-Ueberspannung 3", 121: "Tuer geoeffnet", 125: "Fehler Relaisansteuerung", 126: "Fehler AFI-Messtechnik", 127: "Fehler AC-Spannungsmesstechnik", 128: "Fehler interner Speicher 1", 129: "Spannungsabh. Leistungsreduzierung", } def sendCmdAndRead(ser,cmd): """ send command on rs485 and read answer return list of answered lines if no answer after waiting time, return empty list """ #can only send bytearrays bytearr = cmd.encode() ser.write(bytearr) #print("send to rs485",bytearr) #wait some time to let device answer time.sleep(0.7) answer = [] while ser.inWaiting() > 0: answer.append(ser.readline().decode('ascii')) return ''.join(answer) port = '/dev/ttyUSB0' ser = serial.Serial( port=port, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0.5 ) inverterNumber = 1 s = 0 cmd = '#{:02d}{:01d}\r\n'.format(inverterNumber,s) answer = sendCmdAndRead( ser, cmd ) answer = answer.replace('\r','').replace('\x00','').replace('\n','') l = answer.split() powerdor100to140_gp = ['100TL','120TL','140TL'] if( l[2] in powerdor100to140_gp and l[1]=='20' ): print( "parse({})".format(l[2]) ) StatusText = StatusDict[int(l[3])] StatusCode = l[3] DCVoltage1 = l[4] DCCurrent1 = l[5] DCPower1 = l[6] DCVoltage2 = l[7] DCCurrent2 = l[8] DCPower2 = l[9] ACVoltage1 = l[10] ACCurrent1 = l[11] ACVoltage2 = l[12] ACCurrent2 = l[13] ACVoltage3 = l[14] ACCurrent3 = l[15] DCPowerTotal = l[16] ACPowerTotal = l[17] CosPhi = l[18] CircuitBoardTemp = l[19] DailyYield = l[20] sh.Pv.Kaco120TL.StatusCode(StatusCode) sh.Pv.Kaco120TL.StatusText(StatusText) sh.Pv.Kaco120TL.DCVoltage1( DCVoltage1 ) sh.Pv.Kaco120TL.DCCurrent1(DCCurrent1) sh.Pv.Kaco120TL.DCPower1(DCPower1) sh.Pv.Kaco120TL.DCVoltage2(DCVoltage2) sh.Pv.Kaco120TL.DCCurrent2(DCCurrent2) sh.Pv.Kaco120TL.DCPower2(DCPower2) sh.Pv.Kaco120TL.ACVoltage1(ACVoltage1) sh.Pv.Kaco120TL.ACCurrent1(ACCurrent1) sh.Pv.Kaco120TL.ACVoltage2(ACVoltage2) sh.Pv.Kaco120TL.ACCurrent2(ACCurrent2) sh.Pv.Kaco120TL.ACVoltage3(ACVoltage3) sh.Pv.Kaco120TL.ACCurrent3(ACCurrent3) sh.Pv.Kaco120TL.DCPowerTotal(DCPowerTotal) sh.Pv.Kaco120TL.ACPowerTotal(ACPowerTotal) sh.Pv.Kaco120TL.CosPhi(CosPhi) sh.Pv.Kaco120TL.CircuitBoardTemp(CircuitBoardTemp) sh.Pv.Kaco120TL.DailyYield(DailyYield) ser.close()
Code:
%YAML 1.1 --- Pv: Kaco120TL: StatusCode: type: num sqlite: 'true' StatusText: type: str DCVoltage1: type: num sqlite: 'true' unit: 'Volt' DCCurrent1: type: num sqlite: 'true' unit: 'Ampere' DCPower1: type: num sqlite: 'true' DCVoltage2: type: num sqlite: 'true' unit: 'Volt' DCCurrent2: type: num sqlite: 'true' unit: 'Ampere' DCPower2: type: num sqlite: 'true' ACVoltage1: type: num sqlite: 'true' unit: 'Volt' ACCurrent1: type: num sqlite: 'true' unit: 'Ampere' ACVoltage2: type: num sqlite: 'true' unit: 'Volt' ACCurrent2: type: num sqlite: 'true' unit: 'Ampere' ACVoltage3: type: num sqlite: 'true' unit: 'Volt' ACCurrent3: type: num sqlite: 'true' unit: 'Ampere' DCPowerTotal: type: num sqlite: 'true' unit: 'Watt' ACPowerTotal: type: num sqlite: 'true' unit: 'Watt' CosPhi: type: num sqlite: 'true' CircuitBoardTemp: type: num sqlite: 'true' unit: '° Celsius' DailyYield: type: num sqlite: 'true' unit: 'Wh'
Mein Device sieht so aus.
Code:
[smarthome@SmartHomeNG ~]$ udevadm info --name=/dev/ttyUSB0 --attribute-walk Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB0/tty/ttyUSB0': KERNEL=="ttyUSB0" SUBSYSTEM=="tty" DRIVER=="" looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB0': KERNELS=="ttyUSB0" SUBSYSTEMS=="usb-serial" DRIVERS=="ch341-uart" ATTRS{port_number}=="0" looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0': KERNELS=="1-1.5:1.0" SUBSYSTEMS=="usb" DRIVERS=="ch341" ATTRS{authorized}=="1" ATTRS{bAlternateSetting}==" 0" ATTRS{bInterfaceClass}=="ff" ATTRS{bInterfaceNumber}=="00" ATTRS{bInterfaceProtocol}=="02" ATTRS{bInterfaceSubClass}=="01" ATTRS{bNumEndpoints}=="03" ATTRS{supports_autosuspend}=="1" looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5': KERNELS=="1-1.5" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="ff" ATTRS{bDeviceProtocol}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="8" ATTRS{bMaxPower}=="96mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0254" ATTRS{bmAttributes}=="80" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="5" ATTRS{devpath}=="1.5" ATTRS{idProduct}=="7523" ATTRS{idVendor}=="1a86" ATTRS{ltm_capable}=="no" ATTRS{maxchild}=="0" ATTRS{product}=="USB2.0-Serial" ATTRS{quirks}=="0x0" ATTRS{removable}=="removable" ATTRS{speed}=="12" ATTRS{urbnum}=="299" ATTRS{version}==" 1.10" looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1': KERNELS=="1-1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceProtocol}=="02" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="64" ATTRS{bMaxPower}=="2mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0200" ATTRS{bmAttributes}=="e0" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="2" ATTRS{devpath}=="1" ATTRS{idProduct}=="9514" ATTRS{idVendor}=="0424" ATTRS{ltm_capable}=="no" ATTRS{maxchild}=="5" ATTRS{quirks}=="0x0" ATTRS{removable}=="unknown" ATTRS{speed}=="480" ATTRS{urbnum}=="59" ATTRS{version}==" 2.00" looking at parent device '/devices/platform/soc/3f980000.usb/usb1': KERNELS=="usb1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{authorized_default}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceProtocol}=="01" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="64" ATTRS{bMaxPower}=="0mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0409" ATTRS{bmAttributes}=="e0" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="1" ATTRS{devpath}=="0" ATTRS{idProduct}=="0002" ATTRS{idVendor}=="1d6b" ATTRS{interface_authorized_default}=="1" ATTRS{ltm_capable}=="no" ATTRS{manufacturer}=="Linux 4.9.70-v7+ dwc_otg_hcd" ATTRS{maxchild}=="1" ATTRS{product}=="DWC OTG Controller" ATTRS{quirks}=="0x0" ATTRS{removable}=="unknown" ATTRS{serial}=="3f980000.usb" ATTRS{speed}=="480" ATTRS{urbnum}=="25" ATTRS{version}==" 2.00" looking at parent device '/devices/platform/soc/3f980000.usb': KERNELS=="3f980000.usb" SUBSYSTEMS=="platform" DRIVERS=="dwc_otg" ATTRS{busconnected}=="Bus Connected = 0x1" ATTRS{buspower}=="Bus Power = 0x1" ATTRS{bussuspend}=="Bus Suspend = 0x0" ATTRS{devspeed}=="Device Speed = 0x0" ATTRS{driver_override}=="(null)" ATTRS{enumspeed}=="Device Enumeration Speed = 0x1" ATTRS{fr_interval}=="Frame Interval = 0x1d4b" ATTRS{ggpio}=="GGPIO = 0x00000000" ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306" ATTRS{gotgctl}=="GOTGCTL = 0x001c0001" ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000" ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306" ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a" ATTRS{guid}=="GUID = 0x2708a000" ATTRS{gusbcfg}=="GUSBCFG = 0x20001700" ATTRS{hcd_frrem}=="HCD Dump Frame Remaining" ATTRS{hcddump}=="HCD Dump" ATTRS{hnp}=="HstNegScs = 0x0" ATTRS{hnpcapable}=="HNPCapable = 0x1" ATTRS{hprt0}=="HPRT0 = 0x00001005" ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406" ATTRS{hsic_connect}=="HSIC Connect = 0x1" ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0" ATTRS{mode}=="Mode = 0x1" ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0" ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 1430 msecs (143 jiffies)" ATTRS{regdump}=="Register Dump" ATTRS{regoffset}=="0xffffffff" ATTRS{regvalue}=="invalid offset" ATTRS{rem_wakeup_pwrdn}=="" ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0" ATTRS{spramdump}=="SPRAM Dump" ATTRS{srp}=="SesReqScs = 0x1" ATTRS{srpcapable}=="SRPCapable = 0x1" ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 490 msecs (49 jiffies)" looking at parent device '/devices/platform/soc': KERNELS=="soc" SUBSYSTEMS=="platform" DRIVERS=="" ATTRS{driver_override}=="(null)" looking at parent device '/devices/platform': KERNELS=="platform" SUBSYSTEMS=="" DRIVERS==""
Code:
[smarthome@SmartHomeNG ~]$ cat /etc/udev/rules.d/20-rs485.rules SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB_rs485" [smarthome@SmartHomeNG ~]$
Kann mir da einer weiterhelfen?
VG
Jürgen
Einen Kommentar schreiben: