CControl auslesen

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
alfreds
User
Beiträge: 2
Registriert: Montag 4. Januar 2016, 17:00

Ich möchte ien Conrad CControl auslesen. Das klappt mit meinem Programm, allerdings nur einmal. Die Daten sollen aber ständig ausgelesen werden. Nach Anzeige der Daten häng sich das Programm auf.
Das Programm sieht wie folgt aus:
#!/usr/bin/python3
#----------------------------------------------------------------
# Dateiname: Haus_neu.pyw
# Version 1.0 / 21.09.2016
# (c) Alfred Schwarting
#----------------------------------------------------------------
import time
import serial
from tkinter import *
from time import *
from sys import exit


updateValuesEvery = 5000 #ms

window=Tk()
window.geometry('1000x600+140+100')
window.resizable(width=0, height=0)
canvas=Canvas(window, width=1000, height=600)
canvas.create_line(0, 50, 1000, 50)
canvas.create_line(250, 50, 250, 600)
canvas.create_line(500, 50, 500, 600)
canvas.create_line(750, 50, 750, 600)
canvas.create_rectangle(99, 9 ,900, 35)
canvas.pack()


label_Zeit = Label(master=window, font=("Arial",12), text=asctime(), bg="white")
label_Zeit.place(x=100, y=10, width=800, height=25)

### * Rollosteuerung - Beschriftungen

Label(master=window, font=("Arial",12), text="Rollosteuerung").place(x=65, y=55, width=120, height=20)

Label(master=window, font=("Arial",8), text="Speicher °C").place(x=45, y=102, width=60, height=20)
Label(master=window, font=("Arial",8), text="Speicher °C").place(x=145, y=102, width=60, height=20)
Label(master=window, font=("Arial",8), text="Netz").place(x=45, y=162, width=60, height=20)
Label(master=window, font=("Arial",8), text="Batterie V").place(x=145, y=162, width=60, height=20)
Label(master=window, font=("Arial",8), text="Regen").place(x=45, y=222, width=60, height=20)
Label(master=window, font=("Arial",8), text="Licht").place(x=145, y=222, width=60, height=20)
Label(master=window, font=("Arial",8), text="Rollo WZ").place(x=45, y=282, width=60, height=20)
Label(master=window, font=("Arial",8), text="Rollo SZ").place(x=145, y=282, width=60, height=20)

### * Schwimmbad - Beschriftungen

Label(master=window,font=("Arial",12),text="Schwimmbad").place(x=315, y = 55, width=120, height=20)

Label(master=window,font=("Arial",8),text="Luft °C").place(x=295, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Wasser °C").place(x=395, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Filter Pu.").place(x=295, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="Ventil").place(x=395, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="Hauswasser").place(x=295, y = 222, width=60, height=20)
Label(master=window,font=("Arial",8),text="Lüfter").place(x=395, y = 222, width=60, height=20)

### * Heizung - Beschriftungen

Label(master=window,font=("Arial",12),text="Heizung").place(x=565, y = 55, width=120, height=20)

Label(master=window,font=("Arial",8),text="Aussen °C").place(x=545, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Wasser °C").place(x=645, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Warmw. °C").place(x=545, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="Kessel °C").place(x=645, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="Sollw.Hzg").place(x=545, y = 222, width=60, height=20)
Label(master=window,font=("Arial",8),text="Tag / Nacht").place(x=645, y = 222, width=60, height=20)
Label(master=window,font=("Arial",8),text="Brenner.").place(x=545, y = 282, width=60, height=20)
Label(master=window,font=("Arial",8),text="Teichpumpe").place(x=645, y = 282, width=60, height=20)
Label(master=window,font=("Arial",8),text="Hzg Pu.").place(x=545, y = 342, width=60, height=20)
Label(master=window,font=("Arial",8),text="WW Pu.").place(x=640, y = 342, width=60, height=20)

### * Alarm - Beschriftungen

Label(master=window,font=("Arial",12),text="Alarm").place(x=815, y = 55, width=120, height=20)


Label(master=window,font=("Arial",8),text="Pu Ost").place(x=795, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Pu Keller").place(x=895, y = 102, width=60, height=20)
Label(master=window,font=("Arial",8),text="Pu West").place(x=795, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="12V Pumpe").place(x=895, y = 162, width=60, height=20)
Label(master=window,font=("Arial",8),text="RM SP").place(x=795, y = 222, width=60, height=20)
Label(master=window,font=("Arial",8),text="RM DG").place(x=895, y = 222, width=60, height=20)
Label(master=window,font=("Arial",8),text="RM EG").place(x=795, y = 282, width=60, height=20)
Label(master=window,font=("Arial",8),text="RM KE").place(x=895, y = 282, width=60, height=20)
Label(master=window,font=("Arial",8),text="FE Süd").place(x=790, y = 342, width=60, height=20)
Label(master=window,font=("Arial",8),text="FE Nord").place(x=795, y = 402, width=60, height=20)
Label(master=window,font=("Arial",8),text="Tür Süd").place(x=895, y = 342, width=60, height=20)
Label(master=window,font=("Arial",8),text="Tür Nord").place(x=895, y = 402, width=60, height=20)

# AG Hand / Automatic
Label(master=window, font=("Arial",8), text="Hand / Auto").place(x=45, y=342, width=60, height=20)
# AG Hand / Automatic
Label(master=window, font=("Arial",8), text="Ein / Aus").place(x=145, y=342, width=60, height=20)


### * Rollosteuerung - Werte

Speicher1Temp = StringVar()
Speicher2Temp = StringVar()
AGnetz = StringVar()
AGbatterie = StringVar()
AGregen = StringVar()
AGlicht = StringVar()
AGwz = StringVar()
AGwz_running = BooleanVar()
AGsz = StringVar()
AGsz_running = BooleanVar()

### * Schwimmbad - Werte
AGsl = StringVar()
AGsw = StringVar()
AGfp = StringVar()
AGve = StringVar()
AGhw = StringVar()
AGlue = StringVar()

### * Heizung - Werte
AGhat = StringVar()
AGhwa = StringVar()
AGhww = StringVar()
AGhke = StringVar()
AGhsw = StringVar()
AGhtn = StringVar()
AGhbr = StringVar()
AGtp = StringVar()
AGhhp = StringVar()
AGhwwp = StringVar()

### * Alarm - Werte
AGpo = StringVar()
AGpk = StringVar()
AGpw = StringVar()
AGp12 = StringVar()
AGrsp = StringVar()
AGrdg = StringVar()
AGreg = StringVar()
AGrke = StringVar()
AGfs = StringVar()
AGts = StringVar()
AGfn = StringVar()
AGtn = StringVar()


def WZ_control():
if AGwz_running.get() == True:
button_AGha["text"] = "Aus"
AGwz_running.set(False)
# ..do something..
else:
button_AGha["text"] = "Ein"
AGwz_running.set(True)
# ..do something..

def SZ_control():
if AGsz_running.get() == True:
button_AGea["text"] = "Aus"
AGsz_running.set(False)
# ..do something..
else:
button_AGea["text"] = "Ein"
AGsz_running.set(True)
# ..do something..

## * Rollosteuerung - Ausgabe

# AG Speichertemperatur
label_Speicher1Temp = Label(master=window, font=("Arial",12), textvariable=Speicher1Temp, bg="white")
label_Speicher1Temp.place(x=45, y=80, width=60, height=20)
canvas.create_rectangle(44, 79, 105, 100)
# AG Speichertemperatur
label_Speicher2Temp = Label(master=window, font=("Arial",12), textvariable=Speicher2Temp, bg="white")
label_Speicher2Temp.place(x=145, y=80, width=60, height=20)
canvas.create_rectangle(144, 79, 205, 100)
# AG Netz
label_AGnetz = Label(master=window, font=("Arial",12), textvariable=AGnetz, bg="white")
label_AGnetz.place(x=45, y = 140, width=60, height=20)
canvas.create_rectangle(44, 139, 105, 160)
# AG Batterie
label_AGbatterie = Label(master=window, font=("Arial",12), textvariable=AGbatterie, bg="white")
label_AGbatterie.place(x=145, y=140, width=60, height=20)
canvas.create_rectangle(144, 139, 205, 160)
# AG Regen
label_AGregen = Label(master=window, font=("Arial",12), textvariable=AGregen, bg="white")
label_AGregen.place(x=45, y=200, width=60, height=20)
canvas.create_rectangle(44, 199, 105, 220)
# AG Licht
label_AGlicht = Label(master=window, font=("Arial",12), textvariable=AGlicht, bg="white")
label_AGlicht.place(x=145, y=200, width=60, height=20)
canvas.create_rectangle(144, 199, 205, 220)
# AG Rollo WZ
label_AGwz = Label(master=window, font=("Arial",12), textvariable=AGwz, bg="white")
label_AGwz.place(x=45, y=260, width=60, height=20)
canvas.create_rectangle(44, 259, 105, 280)
# AG Rollo SZ
label_AGsz = Label(master=window, font=("Arial",12), textvariable=AGsz, bg="white")
label_AGsz.place(x=145, y=260, width=60, height=20)
canvas.create_rectangle(144, 259, 205, 280)

## * Schwimmbad - Ausgabe

# AG Schwimmbad Luft
label_AGsl = Label(master=window, font=("Arial",12), textvariable=AGsl, bg="white")
label_AGsl.place(x=295, y = 80, width=60, height=20)
canvas.create_rectangle(294, 79, 355, 100)
# AG Schwimmbad Wasser
label_AGsw = Label(master=window, font=("Arial",12), textvariable=AGsw, bg="white")
label_AGsw.place(x=395, y = 80, width=60, height=20)
canvas.create_rectangle(394, 79, 455, 100)
# AG Filterpumpe
label_AGfp = Label(master=window, font=("Arial",12), textvariable=AGfp, bg="white")
label_AGfp.place(x=295, y = 140, width=60, height=20)
canvas.create_rectangle(294, 139, 355, 160)
# AG Ventil
label_AGve = Label(master=window, font=("Arial",12), textvariable=AGve, bg="white")
label_AGve.place(x=395, y = 140, width=60, height=20)
canvas.create_rectangle(394, 139, 455, 160)
# AG Hauswasserwerk
label_AGhw = Label(master=window, font=("Arial",12), textvariable=AGhw, bg="white")
label_AGhw.place(x=295, y = 200, width=60, height=20)
canvas.create_rectangle(294, 199, 355, 220)
# AG Lüfter
label_AGlue = Label(master=window, font=("Arial",12), textvariable=AGlue, bg="white")
label_AGlue.place(x=395, y = 200, width=60, height=20)
canvas.create_rectangle(394, 199, 455, 220)

## * Heizung - Ausgabe
# AG Heizung Aussen
label_AGhat = Label(master=window, font=("Arial",12), textvariable=AGhat, bg="white")
label_AGhat.place(x=545, y = 80, width=60, height=20)
canvas.create_rectangle(544, 79, 605, 100)
# AG Heizung Wasser
label_AGhwa = Label(master=window, font=("Arial",12), textvariable=AGhwa, bg="white")
label_AGhwa.place(x=645, y = 80, width=60, height=20)
canvas.create_rectangle(644, 79, 705, 100)
# AG Warmwasser
label_AGhww = Label(master=window, font=("Arial",12), textvariable=AGhww, bg="white")
label_AGhww.place(x=545, y = 140, width=60, height=20)
canvas.create_rectangle(544, 139, 605, 160)
# AG Kessel
label_AGhke = Label(master=window, font=("Arial",12), textvariable=AGhke, bg="white")
label_AGhke.place(x=645, y = 140, width=60, height=20)
canvas.create_rectangle(644, 139, 705, 160)
# AG Sollwert
label_AGhsw = Label(master=window, font=("Arial",12), textvariable=AGhsw, bg="white")
label_AGhsw.place(x=545, y = 200, width=60, height=20)
canvas.create_rectangle(544, 199, 605, 220)
# AG Tag/Nacht
label_AGhtn = Label(master=window, font=("Arial",12), textvariable=AGhtn, bg="white")
label_AGhtn.place(x=645, y = 200, width=60, height=20)
canvas.create_rectangle(644, 199, 705, 220)
# AG Brenner
label_AGhbr = Label(master=window, font=("Arial",12), textvariable=AGhbr, bg="white")
label_AGhbr.place(x=545, y = 260, width=60, height=20)
canvas.create_rectangle(544, 259, 605, 280)
# AG Teichpumpe
label_AGtp = Label(master=window, font=("Arial",12), textvariable=AGtp, bg="white")
label_AGtp.place(x=645, y = 260, width=60, height=20)
canvas.create_rectangle(644, 259, 705, 280)
# AG Heizungspumpe
label_AGhhp = Label(master=window, font=("Arial",12), textvariable=AGhhp, bg="white")
label_AGhhp.place(x=545, y = 320, width=60, height=20)
canvas.create_rectangle(544, 319, 605, 340)
# AG Warmwasserpumpe
label_AGhwwp = Label(master=window, font=("Arial",12), textvariable=AGhwwp, bg="white")
label_AGhwwp.place(x=645, y = 320, width=60, height=20)
canvas.create_rectangle(644, 319, 705, 340)

## * Alarm - Ausgabe
# AG Pumpe Ost
label_AGpo = Label(master=window, font=("Arial",12), textvariable=AGpo, bg="white")
label_AGpo.place(x=795, y = 80, width=60, height=20)
canvas.create_rectangle(794, 79, 855, 100)
# AG Pumpe Keller
label_AGpk = Label(master=window, font=("Arial",12), textvariable=AGpk, bg="white")
label_AGpk.place(x=895, y = 80, width=60, height=20)
canvas.create_rectangle(894, 79, 955, 100)
# AG Pumpe West
label_AGpw = Label(master=window, font=("Arial",12), textvariable=AGpw, bg="white")
label_AGpw.place(x=795, y = 140, width=60, height=20)
canvas.create_rectangle(794, 139, 855, 160)
# AG 12V Pumpe
label_AGp12 = Label(master=window, font=("Arial",12), textvariable=AGp12, bg="white")
label_AGp12.place(x=895, y = 140, width=60, height=20)
canvas.create_rectangle(894, 139, 955, 160)
# AG Rauchmelder Speicher
label_AGrsp = Label(master=window, font=("Arial",12), textvariable=AGrsp, bg="white")
label_AGrsp.place(x=795, y = 200, width=60, height=20)
canvas.create_rectangle(794, 199, 855, 220)
# AG Rauchmelder Dachgeschoß
label_AGrdg = Label(master=window, font=("Arial",12), textvariable=AGrdg, bg="white")
label_AGrdg.place(x=895, y = 200, width=60, height=20)
canvas.create_rectangle(894, 199, 955, 220)
# AG Rauchmelder Erdgeschoß
label_AGreg = Label(master=window, font=("Arial",12), textvariable=AGreg, bg="white")
label_AGreg.place(x=795, y = 260, width=60, height=20)
canvas.create_rectangle(794, 259, 855, 280)
# AG Rauchmelder Keller
label_AGrke = Label(master=window, font=("Arial",12), textvariable=AGrke, bg="white")
label_AGrke.place(x=895, y = 260, width=60, height=20)
canvas.create_rectangle(894, 259, 955, 280)
# AG Fenster Süd
label_AGfs = Label(master=window, font=("Arial",12), textvariable=AGfs, bg="white")
label_AGfs.place(x=795, y = 320, width=60, height=20)
canvas.create_rectangle(794, 319, 855, 340)
# AG Tür Süd
label_AGts = Label(master=window, font=("Arial",12), textvariable=AGts, bg="white")
label_AGts.place(x=895, y = 320, width=60, height=20)
canvas.create_rectangle(894, 319, 955, 340)
# AG Fenster Nord
label_AGfn = Label(master=window, font=("Arial",12), textvariable=AGfn, bg="white")
label_AGfn.place(x=795, y = 380, width=60, height=20)
canvas.create_rectangle(794, 379, 855, 400)
# AG Tür Nord
label_AGtn = Label(master=window, font=("Arial",12), textvariable=AGtn, bg="white")
label_AGtn.place(x=895, y = 380, width=60, height=20)
canvas.create_rectangle(894, 379, 955, 400)



## * Schalter - Hand/Automatic

# WZ Hand / Auto
button_AGha = Button(master=window, text="Aus", command=WZ_control, font=("Arial",10), fg="black")
button_AGha.place(x=40, y=320, width=30, height=20)
# SZ Ein / Aus
button_AGea = Button(master=window, text="Aus", command=SZ_control, font=("Arial",10), fg="black")
button_AGea.place(x=140, y = 320, width=30, height=20)


def getValues(serObject):
# for i in range(ord('A'), ord('Z')+1):

#Speicher Ost
writeSerial(serObject, Speicher1Temp, "A")
#Speicher West
writeSerial(serObject, Speicher2Temp, "B")
#AG Netz
writeSerial(serObject, AGnetz, "C")
#AG Batterie
writeSerial(serObject, AGbatterie, "D")
#AG Regen
writeSerial(serObject, AGregen, "E")
#AG Licht
writeSerial(serObject, AGlicht, "F")

#AG SbLuft
writeSerial(serObject, AGsl, "H")
#AG SbWasser
writeSerial(serObject, AGsw, "I")
#AG Filterpumpe
writeSerial(serObject, AGfp, "J")
#AG Ventil
writeSerial(serObject, AGve, "K")
#AG Hauswasser
writeSerial(serObject, AGhw, "L")
#AG Lüfter
writeSerial(serObject, AGlue, "M")

#AG Aussen Hzg
writeSerial(serObject, AGhat, "N")
#AG Wasser Hzg
writeSerial(serObject, AGhwa, "O")
#AG Warmwasser Hzg
writeSerial(serObject, AGhww, "P")
#AG Kessel Hzg
writeSerial(serObject, AGhke, "Q")
#AG Sollwert Hzg
writeSerial(serObject, AGhsw, "R")
#AG Tag/Nacht
writeSerial(serObject, AGhtn, "S")
#AG Brenner Hzg
writeSerial(serObject, AGhbr, "T")
#AG Teichpumpe
writeSerial(serObject, AGtp, "U")
#AG Heizungspumpe
writeSerial(serObject, AGhhp, "V")
#AG Warmwasserpumpe
writeSerial(serObject, AGhwwp, "W")

#AG Pu-Ost Alarm
writeSerial(serObject, AGpo, "X")
#AG Pu-Keller Alarm
writeSerial(serObject, AGpk, "Y")
#AG Pu-West Alarm
writeSerial(serObject, AGpw, "Z")
#AG 12V Pumpe Alarm
writeSerial(serObject, AGp12, "1")
#AG RM Speicher Alarm
writeSerial(serObject, AGrsp, "2")
#AG RM Dachgeschoß Alarm
writeSerial(serObject, AGrdg, "3")
#AG RM Erdgeschoß Alarm
writeSerial(serObject, AGreg, "4")
#AG RM Keller Alarm
writeSerial(serObject, AGrke, "5")
#AG Fesnster Süd Alarm
writeSerial(serObject, AGfs, "6")
#AG Tür Süd Alarm
writeSerial(serObject, AGts, "7")
#AG Fesnter Nord Alarm
writeSerial(serObject, AGfn, "8")
#AG Tür Nord Alarm
writeSerial(serObject, AGtn, "9")


#WZ Hand / Auto
writeSerial(serObject, AGwz, "G")
#SZ Ein / Aus
writeSerial(serObject, AGsz, "m")

window.after(updateValuesEvery, getValues, serObject)



def writeSerial(serObject, value, text):
serObject.write(bytes(text, 'UTF-8'))
while True:
response = serObject.readline().strip()
if response:
break
time.sleep(1)
value.set(response)



### * Serial

ser = serial.Serial()
ser.port = '/dev/ttyUSB0'
# ser.port = 'COM1'
ser.baudrate = 9600
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
#ser.timeout = 1 #non-block read
ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
try:
ser.open()
except Exception as e:
print("Error open serial port: " + str(e))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput() #flush output buffer, aborting current output and discard all that is in buffer
window.after(2000, getValues, ser)
window.mainloop()
except Exception as e:
print("Error...: " + str(e))
except (KeyboardInterrupt, SystemExit):
print("\nSchliesse Programm..\n")
if ser: ser.close()
exit()

# EOF
__deets__
User
Beiträge: 14542
Registriert: Mittwoch 14. Oktober 2015, 14:29

Bitte den Code in die Code Tags setzen, damit man ihn entziffern kann. Das ist der </> Button im erweiterten Editor. Vorschau benuzten und prüfen ob es geklappt hat.

Und Wiederholte Ereignisse macht man in tkinter mit der after Methode. Lang und breit hier um unterforum diskutiert.
alfreds
User
Beiträge: 2
Registriert: Montag 4. Januar 2016, 17:00

Ich habe den Fehler gefunden. Nur die Uhrzeit hat sich nicht erneuert. Die Daten schon.
Antworten