forked from rxhan/RSCPGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrscpguiframe.py
2339 lines (1970 loc) · 113 KB
/
rscpguiframe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import logging
import re
logger = logging.getLogger(__name__)
logger.debug('Programmstart')
import locale
import datetime
import json
import os
import threading
import time
import traceback
import sys
import pytz as pytz
import requests
try:
import paho.mqtt.client as paho
except:
logger.warning('Paho-Libary (paho) nicht gefunden, MQTT wird nicht zur Verfügung stehen')
try:
import wx
import wx.dataview
from export import E3DCExport
from gui import MainFrame
except:
logger.warning('wxPython steht nicht zur Verfügung, Programm beschränkt sich auf die Console')
try:
import telegram
except Exception as e:
logger.warning('Telegram-Libary (python-telegram-bot) nicht gefunden, Telegram-Benachrichtigungen stehen nicht zur Verfügung')
from e3dc._rscp_dto import RSCPDTO
from e3dc.rscp_tag import RSCPTag
from e3dc.rscp_type import RSCPType, WB_TYPE, WB_MODE
from e3dcwebgui import E3DCWebGui
from rscpguimain import RSCPGuiMain
class RSCPGuiFrame(MainFrame, RSCPGuiMain):
class MessageBox(wx.Dialog):
def __init__(self, parent, title, value):
wx.Dialog.__init__(self, parent, title=title)
text = wx.TextCtrl(self, style=wx.TE_READONLY | wx.BORDER_NONE | wx.TE_MULTILINE)
text.SetValue(value)
text.SetBackgroundColour(self.GetBackgroundColour())
self.ShowModal()
self.Destroy()
_time_format = '%d.%m.%Y %H:%M:%S.%f'
_e3dcexportFrame = None
def __init__(self, parent, args):
logger.info('Frame initialisiert')
RSCPGuiMain.__init__(self, args)
MainFrame.__init__(self, parent)
def t(col, ascending = True):
logger.debug('Portal: Sortiere nach Spalte: ' + str(col) + ' Ascending: ' + str(ascending))
if col < self.gPortalList.GetNumberCols():
lst = []
for currow in range(0, self.gPortalList.GetNumberRows()):
data = []
for curcol in range(0, self.gPortalList.GetNumberCols()):
data.append(self.gPortalList.GetCellValue(currow, curcol))
value = self.gPortalList.SortingRowsData[currow][self.gPortalList.SortingColNames[col]]
lst.append((currow, value, data))
result = sorted(lst, key = lambda v: v[1], reverse = ascending)
currow = 0
newrowsdata = []
for oldrow, value, data in result:
newrowsdata.append(self.gPortalList.SortingRowsData[oldrow])
curcol = 0
for value in data:
self.gPortalList.SetCellValue(currow, curcol, value)
curcol += 1
currow += 1
self.gPortalList.SortingRowsData = newrowsdata
else:
return False
self.gPortalList.SortColumn = t
logger.info('Oberfläche geladen')
self.loadConfig()
def load_timezones():
logger.debug('Lade Zeitzonen')
for tz in pytz.common_timezones:
self.cbTimezone.Append(str(tz))
logger.info('Zeitzonen geladen')
threading.Thread(target=load_timezones, args=()).start()
self.cbConfigVerbindungsart.SetValue(self.cfgLoginconnectiontype)
self.Bind(wx.EVT_BUTTON, self.bTestClick, self.bTest)
self.Bind(wx.EVT_BUTTON, self.bSaveClick, self.bSave)
self.Bind(wx.EVT_BUTTON, self.bUpdateClick, self.bUpdate)
self.gDCB_row_voltages = None
self.gDCB_row_temp = None
self._wsthread = threading.Thread(target=self.check_e3dcwebgui, args=())
self._wsthread.start()
def preConnect():
try:
g = self.gui
if self._args.export:
logger.debug('Export bei Programmstart aktiviert')
self.bUploadStartOnClick(None)
if self._args.portal:
self.sendToPortalMin()
except:
pass
threading.Thread(target=preConnect, args=()).start()
self._autothread = threading.Thread(target=self.autoUpdate, args=())
self._autothread.start()
if 'paho' not in sys.modules.keys():
logger.debug('Deaktiviere MQTT-Felder, da MQTT nicht zur Verfügung steht (paho nicht installiert)')
self.enabledisableMQTT(False)
if 'telegram' not in sys.modules.keys():
logger.debug('Deaktiviere Telegram-Benachrichtigungen, da Telegram nicht zur Verfügung steht (python-telegram-bot nicht installiert)')
self.enabledisableTelegram(False)
self.chUploadMQTTOnCheck(None)
self.chUploadInfluxOnCheck(None)
locale.setlocale(locale.LC_ALL, '')
logger.info('Init abgeschlossen')
def enabledisableTelegram(self, value):
self.chBenachrichtigungTelegram.Enable(value)
self.txtTelegramToken.Enable(value)
self.txtTelegramEmpfaenger.Enable(value)
def enabledisableMQTT(self, value):
self.scUploadMQTTQos.Enable(value)
self.chUploadMQTT.Enable(value)
self.chUploadMQTTRetain.Enable(value)
self.txtUploadMQTTBroker.Enable(value)
self.txtUploadMQTTPort.Enable(value)
self.txtUploadMQTTUsername.Enable(value)
self.txtUploadMQTTPassword.Enable(value)
self.fpUploadMQTTZertifikat.Enable(value)
self.cbUploadMQTTInsecure.Enable(value)
self.chUploadMQTTSub.Enable(value)
def hideMQTT(self, value = True):
if value:
self.scUploadMQTTQos.Hide()
#self.chUploadMQTT.Hide()
self.chUploadMQTTRetain.Hide()
self.txtUploadMQTTBroker.Hide()
self.txtUploadMQTTPort.Hide()
self.txtUploadMQTTUsername.Hide()
self.txtUploadMQTTPassword.Hide()
self.fpUploadMQTTZertifikat.Hide()
self.cbUploadMQTTInsecure.Hide()
self.chUploadMQTTSub.Hide()
self.m_staticText214.Hide()
self.m_staticText208.Hide()
self.m_staticText209.Hide()
self.m_staticText2091.Hide()
self.m_staticText2101.Hide()
self.m_staticText210.Hide()
else:
self.scUploadMQTTQos.Show()
#self.chUploadMQTT.Show()
self.chUploadMQTTRetain.Show()
self.txtUploadMQTTBroker.Show()
self.txtUploadMQTTPort.Show()
self.txtUploadMQTTUsername.Show()
self.txtUploadMQTTPassword.Show()
self.fpUploadMQTTZertifikat.Show()
self.cbUploadMQTTInsecure.Show()
self.chUploadMQTTSub.Show()
self.m_staticText214.Show()
self.m_staticText208.Show()
self.m_staticText209.Show()
self.m_staticText2091.Show()
self.m_staticText2101.Show()
self.m_staticText210.Show()
def chUploadMQTTOnCheck(self, event):
if self.chUploadMQTT.GetValue():
self.hideMQTT(False)
else:
self.hideMQTT(True)
parent = self.chUploadMQTT.Parent
parent.GetSizer().Layout()
def hideInflux(self, value = True):
if value:
self.m_staticText213.Hide()
self.m_staticText215.Hide()
self.m_staticText216.Hide()
self.m_staticText217.Hide()
self.m_staticText218.Hide()
self.txtUploadInfluxHost.Hide()
self.txtUploadInfluxPort.Hide()
self.txtUploadInfluxDatenbank.Hide()
self.scUploadInfluxTimeout.Hide()
self.txtUploadInfluxName.Hide()
else:
self.m_staticText213.Show()
self.m_staticText215.Show()
self.m_staticText216.Show()
self.m_staticText217.Show()
self.m_staticText218.Show()
self.txtUploadInfluxHost.Show()
self.txtUploadInfluxPort.Show()
self.txtUploadInfluxDatenbank.Show()
self.scUploadInfluxTimeout.Show()
self.txtUploadInfluxName.Show()
def chUploadInfluxOnCheck(self, event):
if self.chUploadInfluxdb.GetValue():
self.hideInflux(False)
else:
self.hideInflux(True)
parent = self.chUploadInfluxdb.Parent
parent.GetSizer().Layout()
def scAutoUpdateOnChange(self, event):
autoupdate = self.scAutoUpdate.GetValue()
if autoupdate > 0 and self._autothread is None:
self._autothread = threading.Thread(target=self.autoUpdate, args=())
self._autothread.start()
def autoUpdate(self):
while True:
autoupdate = self.scAutoUpdate.GetValue()
if autoupdate == 0:
self._autothread = None
return False
else:
self.pMainChanged()
time.sleep(autoupdate)
def bUploadStartOnClick(self, event):
if not self._AutoExportStarted:
self.refreshConfig()
RSCPGuiMain.StartExport(self)
self.bUploadStart.SetLabel('Export beenden')
else:
self._AutoExportStarted = False
self.bUploadStart.Enable(False)
RSCPGuiMain.StopExport(self)
def StartAutoExport(self):
RSCPGuiMain.StartAutoExport(self)
self.bUploadStart.SetLabel('Export starten')
self.bUploadStart.Enable(True)
def bUploadSetDataOnClick(self, event):
self.bUploadSetData.Enable(False)
if self._e3dcexportFrame:
try:
logger.warning('Exportdialog scheinbar noch geöffnet, schließe Dialog')
self._e3dcexportFrame.Close()
except:
logger.exception('Fehler beim schließen des Exportdialogs')
self._e3dcexportFrame = E3DCExport(self, paths=self.cfgExportpaths, names = self.cfgExportpathnames)
self._e3dcexportFrame.Bind(wx.EVT_CLOSE, self.ExportFrameOnClose)
self._e3dcexportFrame.Show()
def ExportFrameOnClose(self, event):
logger.debug('Exportfenster wurde geschlossen')
self.cfgExportpaths = self._e3dcexportFrame.getExportPaths()
self.cfgExportpathnames = self._e3dcexportFrame.getCustomNames()
if len(self.cfgExportpaths) != len(self.cfgExportpathnames):
logger.error('Ausgewählte Pfadanzahl stimmt nicht mit Bezeichneranzahl überein')
self.stUploadCount.SetLabel('Es wurden ' + str(len(self.cfgExportpaths)) + ' Datenfelder angewählt')
for path in self.cfgExportpaths:
if path in self._e3dcexportFrame._customNames:
custom = self._e3dcexportFrame._customNames[path]
logger.debug('Pfad: ' + path + ' angewählt und gespeichert unter dem Namen ' + custom)
else:
logger.debug('Pfad: ' + path + ' angewählt und gespeichert')
self.bUploadSetData.Enable(True)
self._e3dcexportFrame = None
event.Skip()
def pMainChanged(self, event=None):
self.updateTab()
def updateTab(self, page = None):
if page is None:
page = self.pMainregister.GetCurrentPage()
if not self._updateRunning:
self._updateRunning = True
self.disableButtons()
self.gaUpdate.SetValue(0)
name = page.GetName()
try:
logger.debug('Aktualisiere ' + name)
if page == self.pPortal:
try:
self.fill_portal()
except:
logger.exception('Fehler beim Darstellen der Portal-Daten')
elif page == self.pBenachrichtigungen:
try:
self.fill_benachrichtigungen()
except:
logger.exception('Fehler beim Darstellen der Benachrichtigung')
elif self.gui:
if page == self.pDCDC:
try:
self.fill_dcdc()
except:
logger.exception('Fehler beim Abruf der DCDC-Daten')
elif page == self.pMain:
try:
self.fill_info()
except:
logger.exception('Fehler beim Abruf der INFO-Daten')
elif page == self.pBAT:
try:
self.fill_bat()
self.gDCB.AutoSizeRows()
self.gDCB.AutoSizeColumns()
except:
logger.exception('Fehler beim Abruf der BAT-Daten')
elif page == self.pPVI:
try:
self.fill_pvi()
except:
logger.exception('Fehler beim Abruf der PVI-Daten')
elif page == self.pEMS:
try:
p2 = self.m_notebook2.GetCurrentPage()
if p2 == self.m_panel11: # Modbus
self.fill_mbs()
elif p2 == self.m_panel9: # SYS
self.fill_ems_sys()
elif p2 == self.m_panel8: # Ladeeinstellungen
self.fill_ems_power()
elif p2 == self.m_panel7: # Basis
self.fill_ems_basis()
except:
logger.exception('Fehler beim Abruf der EMS-Daten')
elif page == self.pPM:
try:
self.fill_pm()
except:
logger.exception('Fehler beim Abruf der PM-Daten')
elif page == self.pWB:
try:
self.fill_wb()
except:
logger.exception('Fehler beim Abruf der WB-Daten')
else:
logger.warning('Konfiguration unvollständig, Verbindung nicht möglich')
except:
logger.exception('Fehler beim Aktualisieren von ' + name)
self.gaUpdate.SetValue(100)
self.enableButtons()
self._updateRunning = False
@property
def gui(self):
if self._gui:
if self.cfgLoginusername == self.txtUsername.GetValue() and self.cfgLoginpassword == self.txtPassword.GetValue() and \
self.cfgLoginaddress == self.txtIP.GetValue() and self.cfgLoginrscppassword == self.txtRSCPPassword.GetValue() and \
self.cfgLoginseriennummer == self.txtConfigSeriennummer.GetValue() and \
self.cfgLoginconnectiontype == self.cbConfigVerbindungsart.GetValue():
return self._gui
self.cfgLoginusername = self.txtUsername.GetValue()
self.cfgLoginpassword = self.txtPassword.GetValue()
self.cfgLoginaddress = self.txtIP.GetValue()
self.cfgLoginrscppassword = self.txtRSCPPassword.GetValue()
self.cfgLoginseriennummer = self.txtConfigSeriennummer.GetValue()
self.cfgLoginconnectiontype = self.cbConfigVerbindungsart.GetValue()
if isinstance(self._gui, E3DCWebGui):
self._gui.e3dc.ws.close()
return RSCPGuiMain.gui.fget(self)
def bEMSUploadChangesOnClick(self, event):
if self._data_ems is None:
RSCPGuiMain.fill_ems(self)
r = []
test = 1 if self.chEMSBatteryBeforeCarMode.GetValue() == False else 0
if test != self._data_ems['EMS_BATTERY_BEFORE_CAR_MODE'].data:
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_BATTERY_BEFORE_CAR_MODE, rscp_type=RSCPType.UChar8, data=test))
test = 0 if self.chEMSBatteryToCarMode.GetValue() == False else 1
if test != self._data_ems['EMS_BATTERY_TO_CAR_MODE'].data:
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_BATTERY_TO_CAR_MODE, rscp_type=RSCPType.UChar8, data=test))
temp = []
test = self.chEMSPowerLimitsUsed.GetValue()
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_POWER_LIMITS_USED'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_POWER_LIMITS_USED, rscp_type=RSCPType.Bool, data=test))
test = 1 if self.chEMSPowerSaveEnabled.GetValue() else 0
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_POWERSAVE_ENABLED'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_POWERSAVE_ENABLED, rscp_type=RSCPType.UChar8, data=test))
test = 1 if self.chEMSWeatherRegulatedChargeEnabled.GetValue() else 0
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_WEATHER_REGULATED_CHARGE_ENABLED'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_WEATHER_REGULATED_CHARGE_ENABLED, rscp_type=RSCPType.UChar8, data=test))
test = self.sEMSMaxChargePower.GetValue()
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_MAX_CHARGE_POWER'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_MAX_CHARGE_POWER, rscp_type=RSCPType.Uint32, data=test))
test = self.sEMSMaxDischargePower.GetValue()
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_MAX_DISCHARGE_POWER'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_MAX_DISCHARGE_POWER, rscp_type=RSCPType.Uint32, data=test))
test = self.sEMSMaxDischargeStartPower.GetValue()
if test != self._data_ems['EMS_GET_POWER_SETTINGS']['EMS_DISCHARGE_START_POWER'].data:
temp.append(RSCPDTO(tag=RSCPTag.EMS_DISCHARGE_START_POWER, rscp_type=RSCPType.Uint32, data=test))
if len(temp) > 0:
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_POWER_SETTINGS, rscp_type=RSCPType.Container, data=temp))
days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
for idlePeriod in self._data_ems['EMS_GET_IDLE_PERIODS']['EMS_IDLE_PERIOD']:
if idlePeriod['EMS_IDLE_PERIOD_TYPE'].data == 0:
c = 'Charge'
else:
c = 'Discharge'
day = days[int(idlePeriod['EMS_IDLE_PERIOD_DAY'])]
von = 'tpEMS' + c + day + 'Von'
bis = 'tpEMS' + c + day + 'Bis'
ch = 'chEMS' + c + day
ch_data = self.__getattribute__(ch).GetValue()
von_data = self.__getattribute__(von).GetValue().split(':')
if len(von_data) == 2:
von_data_hour = int(von_data[0])
von_data_minute = int(von_data[1])
else:
wx.MessageBox('Dateneingabe im Feld ' + von + ' ist falsch', 'Ladeeinstellungen speichern', wx.ICON_WARNING)
raise Exception('Dateneingabe im Feld ' + von + ' falsch')
bis_data = self.__getattribute__(bis).GetValue().split(':')
if len(bis_data) == 2:
bis_data_hour = int(bis_data[0])
bis_data_minute = int(bis_data[1])
else:
wx.MessageBox('Dateneingabe im Feld ' + bis + ' ist falsch', 'Ladeeinstellungen speichern', wx.ICON_WARNING)
raise Exception('Dateneingabe im Feld ' + bis + ' falsch')
if idlePeriod['EMS_IDLE_PERIOD_ACTIVE'].data != ch_data or \
idlePeriod['EMS_IDLE_PERIOD_START']['EMS_IDLE_PERIOD_HOUR'].data != von_data_hour or \
idlePeriod['EMS_IDLE_PERIOD_START']['EMS_IDLE_PERIOD_MINUTE'].data != von_data_minute or \
idlePeriod['EMS_IDLE_PERIOD_END']['EMS_IDLE_PERIOD_HOUR'].data != bis_data_hour or \
idlePeriod['EMS_IDLE_PERIOD_END']['EMS_IDLE_PERIOD_MINUTE'].data != bis_data_minute:
res = self.gui.setIdlePeriod(type=idlePeriod['EMS_IDLE_PERIOD_TYPE'].data,
active=ch_data,
day=idlePeriod['EMS_IDLE_PERIOD_DAY'].data,
start=str(von_data_hour).zfill(2) + ':' + str(von_data_minute).zfill(2),
end=str(bis_data_hour).zfill(2) + ':' + str(bis_data_minute).zfill(2))
r += res
if len(r) > 0:
try:
res = self.gui.get_data(r, True)
wx.MessageBox('Übertragung abgeschlossen')
except:
traceback.print_exc()
wx.MessageBox('Übertragung fehlgeschlagen')
else:
res = wx.MessageBox('Es wurden keine Änderungen gemacht, aktuelle Einstellungen trotzdem übertragen?',
'Ladeeinstellungen speichern', wx.YES_NO)
if res == wx.YES:
test = 1 if self.chEMSBatteryBeforeCarMode.GetValue() == False else 0
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_BATTERY_BEFORE_CAR_MODE, rscp_type=RSCPType.UChar8, data=test))
test = 0 if self.chEMSBatteryToCarMode.GetValue() == False else 1
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_BATTERY_TO_CAR_MODE, rscp_type=RSCPType.UChar8, data=test))
temp = []
test = self.chEMSPowerLimitsUsed.GetValue()
temp.append(RSCPDTO(tag=RSCPTag.EMS_POWER_LIMITS_USED, rscp_type=RSCPType.Bool, data=test))
test = 1 if self.chEMSPowerSaveEnabled.GetValue() else 0
temp.append(RSCPDTO(tag=RSCPTag.EMS_POWERSAVE_ENABLED, rscp_type=RSCPType.UChar8, data=test))
test = 1 if self.chEMSWeatherRegulatedChargeEnabled.GetValue() else 0
temp.append(
RSCPDTO(tag=RSCPTag.EMS_WEATHER_REGULATED_CHARGE_ENABLED, rscp_type=RSCPType.UChar8, data=test))
test = self.sEMSMaxChargePower.GetValue()
temp.append(RSCPDTO(tag=RSCPTag.EMS_MAX_CHARGE_POWER, rscp_type=RSCPType.Uint32, data=test))
test = self.sEMSMaxDischargePower.GetValue()
temp.append(RSCPDTO(tag=RSCPTag.EMS_MAX_DISCHARGE_POWER, rscp_type=RSCPType.Uint32, data=test))
test = self.sEMSMaxDischargeStartPower.GetValue()
temp.append(RSCPDTO(tag=RSCPTag.EMS_DISCHARGE_START_POWER, rscp_type=RSCPType.Uint32, data=test))
r.append(RSCPDTO(tag=RSCPTag.EMS_REQ_SET_POWER_SETTINGS, rscp_type=RSCPType.Container, data=temp))
try:
res = self.gui.get_data(r, True)
wx.MessageBox('Übertragung abgeschlossen')
except:
traceback.print_exc()
wx.MessageBox('Übertragung fehlgeschlagen')
self.fill_ems()
def set_wb_enabled(self):
def set_wb_enableddisabled(value):
self.bWBSave.Enable(value)
self.chWB1PH.Enable(value)
self.chWBSunmode.Enable(value)
self.sWBLadestrom.Enable(value)
self.bWBStopLoading.Enable(value)
if len(self._data_wb) > 0:
set_wb_enableddisabled(True)
else:
set_wb_enableddisabled(False)
if self.txtWBMode.GetValue() == 'LOADING':
self.bWBStopLoading.SetLabel('Ladevorgang abbrechen')
else:
self.bWBStopLoading.SetLabel('Ladevorgang starten')
def bWBStopLoadingClick(self, event):
index = self.cbWallbox.GetSelection()
if len(self._data_wb) > index:
res = wx.MessageBox('Soll der Ladevorgang in WB#' + str(index) + ' wirklich abgebrochen werden?',
'Wallbox Ladevorgang abbrechen', wx.YES_NO | wx.ICON_QUESTION)
if res == wx.YES:
try:
ba = bytearray(6)
ba[4] = 1
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_EXTERN, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=ba),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
print(req_data)
res = self.gui.get_data([req_data], True)
print(res)
wx.MessageBox('Übertragung durchgeführt')
except:
traceback.print_exc()
wx.MessageBox('Übertragung fehlgeschlagen')
else:
wx.MessageBox('Wallbox #' + str(index) + ' existiert nicht, dieser Fehler sollte nicht auftreten!')
logger.error('Wallbox #' + str(index) + ' existiert nicht!')
self.pMainChanged()
def bWBSaveOnClick(self, event):
index = self.cbWallbox.GetSelection()
data = self._data_wb[index]
index = data['WB_INDEX'].data
r = []
test_changed = self.chWBSunmode.GetValue()
test_orig = (data['WB_EXTERN_DATA_ALG']['WB_EXTERN_DATA'].data[2] & 128) == 128
if test_changed != test_orig:
ba = bytearray(6)
ba[0] = 1 if test_changed else 2
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_EXTERN, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=ba),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
test_changed = self.chWB1PH.GetValue()
test_orig = (data['WB_EXTERN_DATA_ALG']['WB_EXTERN_DATA'].data[1] == 1)
if test_changed != test_orig:
ba = bytearray(6)
ba[3] = 1 if test_changed else 3
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_EXTERN, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=ba),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
test_changed = self.sWBLadestrom.GetValue()
param_1 = bytearray(data['WB_RSP_PARAM_1']['WB_EXTERN_DATA'].data)
if test_changed != param_1[2]:
param_1[2] = test_changed
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_PARAM_1, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=param_1),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
for i in r:
print(i)
if len(r) > 0:
try:
res = self.gui.get_data(r, True)
print(res)
wx.MessageBox('Übertragung abgeschlossen')
except:
traceback.print_exc()
wx.MessageBox('Übertragung fehlgeschlagen')
else:
res = wx.MessageBox('Es wurden keine Änderungen gemacht, aktuelle Einstellungen trotzdem übertragen?',
'Wallbox speichern', wx.YES_NO)
if res == wx.YES:
r = []
test_changed = self.chWBSunmode.GetValue()
ba = bytearray(6)
ba[0] = 1 if test_changed else 2
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_EXTERN, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=ba),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
test_changed = self.chWB1PH.GetValue()
ba = bytearray(6)
ba[3] = 1 if test_changed else 3
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_EXTERN, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=ba),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
test_changed = self.sWBLadestrom.GetValue()
param_1[2] = test_changed
req_data = RSCPDTO(tag=RSCPTag.WB_REQ_DATA, rscp_type=RSCPType.Container)
req_data += RSCPDTO(tag=RSCPTag.WB_INDEX, rscp_type=RSCPType.UChar8, data=index)
req_data += RSCPDTO(tag=RSCPTag.WB_REQ_SET_PARAM_1, rscp_type=RSCPType.Container, data=
[RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA, rscp_type=RSCPType.ByteArray, data=param_1),
RSCPDTO(tag=RSCPTag.WB_EXTERN_DATA_LEN, rscp_type=RSCPType.UChar8, data=6)]
)
r.append(req_data)
for i in r:
print(i)
try:
res = self.gui.get_data(r, True)
print(res)
wx.MessageBox('Übertragung abgeschlossen')
except:
traceback.print_exc()
wx.MessageBox('Übertragung fehlgeschlagen')
self.pMainChanged()
def sEMSMaxChargePowerOnScroll(self, event):
self.txtEMSMaxChargePower.SetValue(str(self.sEMSMaxChargePower.GetValue()) + ' W')
def sEMSMaxDischargePowerOnScroll(self, event):
self.txtEMSMaxDischargePower.SetValue(str(self.sEMSMaxDischargePower.GetValue()) + ' W')
def sEMSMaxDischargeStartPowerOnScroll(self, event):
self.txtEMSMaxDischargeStartPower.SetValue(str(self.sEMSMaxDischargeStartPower.GetValue()) + ' W')
def fill_info(self):
RSCPGuiMain.fill_info(self)
d = self._data_info
self.txtProductionDate.SetValue(repr(d['INFO_PRODUCTION_DATE']))
self.txtSerialnumber.SetValue(repr(d['INFO_SERIAL_NUMBER']))
self.txtSwRelease.SetValue(repr(d['INFO_SW_RELEASE']))
self.txtA35Serial.SetValue(repr(d['INFO_A35_SERIAL_NUMBER']))
dd = datetime.datetime.utcfromtimestamp(float(d['INFO_TIME'].data))
self.txtTime.SetValue(str(dd.strftime(self._time_format)))
self.cbTimezone.SetValue(repr(d['INFO_TIME_ZONE']))
dd = datetime.datetime.utcfromtimestamp(float(d['INFO_UTC_TIME'].data))
self.txtTimeUTC.SetValue(str(dd))
self.txtUpdateStatus.SetValue(repr(d['UM_UPDATE_STATUS']))
self.txtIPAdress.SetValue(repr(d['INFO_IP_ADDRESS']))
self.txtSubnetmask.SetValue(repr(d['INFO_SUBNET_MASK']))
self.txtMacAddress.SetValue(repr(d['INFO_MAC_ADDRESS']))
self.txtGateway.SetValue(repr(d['INFO_GATEWAY']))
self.txtDNSServer.SetValue(repr(d['INFO_DNS']))
self.chDHCP.SetValue(d['INFO_DHCP_STATUS'].data)
self.chSRVIsOnline.SetValue(d['SRV_IS_ONLINE'].data)
self.chSYSReboot.SetValue(d['SYS_IS_SYSTEM_REBOOTING'].data)
self.txtRSCPUserLevel.SetValue(repr(d['RSCP_USER_LEVEL']))
self.gInfoFilesystem.SetValue(int(d['INFO_GET_FS_USAGE']['INFO_FS_USE_PERCENT'].data[:-1]))
self.txtFilesystemPercent.SetValue(repr(d['INFO_GET_FS_USAGE']['INFO_FS_USE_PERCENT']))
ts = repr(d['INFO_GET_FS_USAGE']['INFO_FS_USED']) + ' von ' + repr(d['INFO_GET_FS_USAGE']['INFO_FS_SIZE']) + ' in Verwendung, ' + repr(d['INFO_GET_FS_USAGE']['INFO_FS_AVAILABLE']) + ' frei'
self.txtFilesystem.SetValue(ts)
if 'INFO_MODULES_SW_VERSIONS' in d:
self.gSoftwaremodules.Show()
self.gSoftwaremodules.DeleteRows(0, self.gSoftwaremodules.GetNumberRows())
self.gSoftwaremodules.AppendRows(len(d['INFO_MODULES_SW_VERSIONS']))
row = 0
regex = r"([\d\.]*) \[(.*)\] \(SVN:([\da-zA-Z]*)\)"
for moduleversion in d['INFO_MODULES_SW_VERSIONS']:
module = moduleversion['INFO_MODULE'].data
self.gSoftwaremodules.SetCellValue(row, 0, module)
versiondata = moduleversion['INFO_VERSION'].data
try:
matches = re.findall(regex, versiondata)[0]
version = matches[0]
dt = matches[1]
svn = matches[2]
self.gSoftwaremodules.SetCellValue(row, 1, version)
self.gSoftwaremodules.SetCellValue(row, 2, dt)
self.gSoftwaremodules.SetCellValue(row, 3, svn)
except Exception as e:
self.gSoftwaremodules.SetCellValue(row, 1, versiondata)
logger.error('Fehler beim Parsen der Modul-Software-Versionen (' + str(module) + ' / ' + str(versiondata) + '): ' + str(e))
row+=1
self.gSoftwaremodules.AutoSizeColumns()
else:
self.gSoftwaremodules.Hide()
def fill_ems(self):
RSCPGuiMain.fill_ems(self)
d = self._data_ems
self.fill_ems_basis(d)
self.fill_ems_sys(d['EMS_GET_SYS_SPECS'])
self.fill_ems_power(d)
def fill_ems_basis(self, d = None):
if not d:
d = self.gui.get_data(self.gui.getEMSBasis(), True)
self.txtEMSPowerPV.SetValue(repr(d['EMS_POWER_PV']) + ' W')
self.txtEMSPowerHome.SetValue(repr(d['EMS_POWER_HOME']) + ' W')
self.txtEMSPowerBat.SetValue(repr(d['EMS_POWER_BAT']) + ' W')
self.txtEMSPowerGrid.SetValue(repr(d['EMS_POWER_GRID']) + ' W')
self.txtEMSPowerAdd.SetValue(repr(d['EMS_POWER_ADD']) + ' W')
self.txtEMSAutarkie.SetValue(str(round(d['EMS_AUTARKY'], 2)) + ' %')
self.gEMSAutarkie.SetValue(int(round(d['EMS_AUTARKY'], 0)))
self.txtEMSSelfConsumption.SetValue(str(round(d['EMS_SELF_CONSUMPTION'], 2)) + ' %')
self.gEMSSelfConsumption.SetValue(int(round(d['EMS_SELF_CONSUMPTION'], 0)))
self.txtEMSBatSoc.SetValue(str(round(d['EMS_BAT_SOC'], 2)) + ' %')
self.mgEMSBatSoc.SetValue(round(d['EMS_BAT_SOC'], 0))
self.txtEMSCouplingMode.SetValue(repr(d['EMS_COUPLING_MODE']))
self.txtEMSMode.SetValue(repr(d['EMS_MODE']))
balancedphases = "{0:b}".format(d['EMS_BALANCED_PHASES'].data).replace('1', 'X ').replace('0', '0 ')
self.txtEMSBalancedPhases.SetValue(balancedphases)
self.txtEMSExtSrcAvailable.SetValue(repr(d['EMS_EXT_SRC_AVAILABLE']))
self._extsrcavailable = d['EMS_EXT_SRC_AVAILABLE'].data
self.txtEMSInstalledPeakPower.SetValue(repr(d['EMS_INSTALLED_PEAK_POWER']) + ' Wp')
self.txtEMSDerateAtPercent.SetValue(str(round(d['EMS_DERATE_AT_PERCENT_VALUE'], 3) * 100) + ' %')
self.txtEMSDerateAtPower.SetValue(repr(d['EMS_DERATE_AT_POWER_VALUE']) + ' W')
self.txtEMSUsedChargeLimit.SetValue(repr(d['EMS_USED_CHARGE_LIMIT']) + ' W')
self.txtEMSUserChargeLimit.SetValue(repr(d['EMS_USER_CHARGE_LIMIT']) + ' W')
self.txtEMSBatChargeLimit.SetValue(repr(d['EMS_BAT_CHARGE_LIMIT']) + ' W')
self.txtEMSDCDCChargeLimit.SetValue(repr(d['EMS_DCDC_CHARGE_LIMIT']) + ' W')
self.txtEMSRemainingBatChargePower.SetValue(repr(d['EMS_REMAINING_BAT_CHARGE_POWER']) + ' W')
self.txtEMSUsedDischargeLimit.SetValue(repr(d['EMS_USED_DISCHARGE_LIMIT']) + ' W')
self.txtEMSUserDischargeLimit.SetValue(repr(d['EMS_USER_DISCHARGE_LIMIT']) + ' W')
self.txtEMSBatDischargeLimit.SetValue(repr(d['EMS_BAT_DISCHARGE_LIMIT']) + ' W')
self.txtEMSDCDCDischargeLimit.SetValue(repr(d['EMS_DCDC_DISCHARGE_LIMIT']) + ' W')
self.txtEMSRemainingBatDischargePower.SetValue(repr(d['EMS_REMAINING_BAT_DISCHARGE_POWER']) + ' W')
self.txtEMSEmergencyPowerStatus.SetValue(repr(d['EMS_EMERGENCY_POWER_STATUS']))
self.txtEMSStatus.SetValue(repr(d['EMS_STATUS']))
eptest = d['EMS_EMERGENCYPOWER_TEST_STATUS']['EMS_EPTEST_RUNNING'].data
if eptest:
self.bEMSEPTest.Enable(False)
else:
self.bEMSEPTest.Enable(True)
self.chEMSEPTestRunning.SetValue(eptest)
self.txtEMSEPTestCounter.SetValue(repr(d['EMS_EMERGENCYPOWER_TEST_STATUS']['EMS_EPTEST_START_COUNTER']))
self.txtEMSEPTestTimestamp.SetValue(repr(d['EMS_EMERGENCYPOWER_TEST_STATUS']['EMS_EPTEST_NEXT_TESTSTART']))
self.txtEMSPowerWBAll.SetValue(repr(d['EMS_POWER_WB_ALL']) + ' W')
self.txtEMSPowerWBSolar.SetValue(repr(d['EMS_POWER_WB_SOLAR']) + ' W')
self.chEMSAlive.SetValue(d['EMS_ALIVE'].data)
manChargeActive = d['EMS_GET_MANUAL_CHARGE']['EMS_MANUAL_CHARGE_ACTIVE'].data
self.chEMSGetManualCharge.SetValue(manChargeActive)
if manChargeActive:
self.bEMSManualChargeStart.Enable(False)
else:
self.bEMSManualChargeStart.Enable(True)
startcounter = d['EMS_GET_MANUAL_CHARGE']['EMS_MANUAL_CHARGE_START_COUNTER'].data / 1000
dd = datetime.datetime.fromtimestamp(startcounter)
self.txtEMSManualChargeStartCounter.SetValue(dd.strftime(self._time_format))
self.txtEMSManualChargeEnergyCounter.SetValue(str(
round(d['EMS_GET_MANUAL_CHARGE']['EMS_MANUAL_CHARGE_ENERGY_COUNTER'], 5)) + ' kWh') # TODO: Einheit anfügen
laststart = d['EMS_GET_MANUAL_CHARGE']['EMS_MANUAL_CHARGE_LASTSTART'].data
dd = datetime.datetime.fromtimestamp(laststart)
self.txtEMSManualChargeLaststart.SetValue(dd.strftime(self._time_format))
self.chEPIsland.SetValue(d['EP_IS_ISLAND_GRID'].data)
self.chEPReadyForSwitch.SetValue(d['EP_IS_READY_FOR_SWITCH'].data)
self.chEPISGridConnected.SetValue(d['EP_IS_GRID_CONNECTED'].data)
self.chEPPossible.SetValue(d['EP_IS_POSSIBLE'].data)
self.chEPInvalid.SetValue(d['EP_IS_INVALID_STATE'].data)
def fill_ems_power(self, d = None):
if not d:
d = self.gui.get_data(self.gui.getEMSPowerSettings() + self.gui.getEMSIdlePeriods() + self.gui.getEMSSysSpecs(), True)
for sysspec in d['EMS_GET_SYS_SPECS']['EMS_SYS_SPEC']:
if sysspec['EMS_SYS_SPEC_NAME'].data == 'maxStartChargePower':
self.sEMSMaxDischargeStartPower.SetMax(sysspec['EMS_SYS_SPEC_VALUE_INT'].data)
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxChargePower':
self.sEMSMaxChargePower.SetMax(sysspec['EMS_SYS_SPEC_VALUE_INT'].data)
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxDischargePower':
self.sEMSMaxDischargePower.SetMax(sysspec['EMS_SYS_SPEC_VALUE_INT'].data)
self.sEMSMaxChargePower.SetValue(d['EMS_GET_POWER_SETTINGS']['EMS_MAX_CHARGE_POWER'].data)
self.txtEMSMaxChargePower.SetValue(repr(d['EMS_GET_POWER_SETTINGS']['EMS_MAX_CHARGE_POWER']) + ' W')
self.sEMSMaxDischargePower.SetValue(d['EMS_GET_POWER_SETTINGS']['EMS_MAX_DISCHARGE_POWER'].data)
self.txtEMSMaxDischargePower.SetValue(repr(d['EMS_GET_POWER_SETTINGS']['EMS_MAX_DISCHARGE_POWER']) + ' W')
self.sEMSMaxDischargeStartPower.SetValue(d['EMS_GET_POWER_SETTINGS']['EMS_DISCHARGE_START_POWER'].data)
self.txtEMSMaxDischargeStartPower.SetValue(repr(d['EMS_GET_POWER_SETTINGS']['EMS_DISCHARGE_START_POWER']) + ' W')
self.chEMSPowerLimitsUsed.SetValue(d['EMS_GET_POWER_SETTINGS']['EMS_POWER_LIMITS_USED'].data)
self.chEMSPowerSaveEnabled.SetValue(d['EMS_GET_POWER_SETTINGS']['EMS_POWERSAVE_ENABLED'].data)
self.chEMSWeatherRegulatedChargeEnabled.SetValue(
d['EMS_GET_POWER_SETTINGS']['EMS_WEATHER_REGULATED_CHARGE_ENABLED'].data)
if d['EMS_BATTERY_BEFORE_CAR_MODE'].data == 1:
self.chEMSBatteryBeforeCarMode.SetValue(False)
else:
self.chEMSBatteryBeforeCarMode.SetValue(True)
if d['EMS_BATTERY_TO_CAR_MODE'].data == 1:
self.chEMSBatteryToCarMode.SetValue(True)
else:
self.chEMSBatteryToCarMode.SetValue(False)
days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
for idlePeriod in d['EMS_GET_IDLE_PERIODS']['EMS_IDLE_PERIOD']:
if idlePeriod['EMS_IDLE_PERIOD_TYPE'].data == 0:
c = 'Charge'
else:
c = 'Discharge'
day = days[int(idlePeriod['EMS_IDLE_PERIOD_DAY'])]
von = 'tpEMS' + c + day + 'Von'
bis = 'tpEMS' + c + day + 'Bis'
ch = 'chEMS' + c + day
self.__getattribute__(ch).SetValue(idlePeriod['EMS_IDLE_PERIOD_ACTIVE'].data)
self.__getattribute__(von).SetValue(
str(idlePeriod['EMS_IDLE_PERIOD_START']['EMS_IDLE_PERIOD_HOUR'].data).zfill(2) + ':' + str(
idlePeriod['EMS_IDLE_PERIOD_START']['EMS_IDLE_PERIOD_MINUTE'].data).zfill(2))
self.__getattribute__(bis).SetValue(
str(idlePeriod['EMS_IDLE_PERIOD_END']['EMS_IDLE_PERIOD_HOUR'].data).zfill(2) + ':' + str(
idlePeriod['EMS_IDLE_PERIOD_END']['EMS_IDLE_PERIOD_MINUTE'].data).zfill(2))
def fill_ems_sys(self, d = None):
if not d:
d = self.gui.get_data(self.gui.getEMSSysSpecs(), True)
for sysspec in d['EMS_SYS_SPEC']:
if sysspec['EMS_SYS_SPEC_NAME'].data == 'hybridModeSupported':
self.txtEMSHybridModeSupported.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'installedBatteryCapacity':
self.txtEMSInstalledBatteryCapacity.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxAcPower':
self.txtEMSMaxAcPower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxBatChargePower':
self.txtEMSMaxBatChargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxBatDischargPower':
self.txtEMSMaxBatDischargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxChargePower':
self.txtEMSMaxChargePowerSys.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxDischargePower':
self.txtEMSMaxDischargePowerSys.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxFbcChargePower':
self.txtEMSMaxFbcDischargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxPvPower':
self.txtEMSMaxPVPower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxStartChargePower':
self.txtEMSMaxStartChargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
maxStartChargePower = int(sysspec['EMS_SYS_SPEC_VALUE_INT'])
self.sEMSMaxChargePower.Max = maxStartChargePower
self.sEMSMaxDischargeStartPower.Max = maxStartChargePower
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'maxStartDischargePower':
self.txtEMSMaxStartDischargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
maxStartDischargePower = int(sysspec['EMS_SYS_SPEC_VALUE_INT'])
self.sEMSMaxDischargePower.Max = maxStartDischargePower
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'minStartChargePower':
self.txtEMSMinStartChargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
minStartChargePower = int(sysspec['EMS_SYS_SPEC_VALUE_INT'])
self.sEMSMaxChargePower.Min = minStartChargePower
self.sEMSMaxDischargeStartPower.Min = minStartChargePower
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'minStartDischargePower':
self.txtEMSMinStartDischargePower.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
minStartDischargePower = int(sysspec['EMS_SYS_SPEC_VALUE_INT'])
self.sEMSMaxDischargePower.Min = minStartDischargePower
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'recommendedMinChargeLimit':
self.txtEMSRecommendedMinChargeLimit.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'recommendedMinDischargeLimit':
self.txtEMSRecommendedMinDischargeLimit.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'startChargeDefault':
self.txtEMSstartChargeDefault.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
elif sysspec['EMS_SYS_SPEC_NAME'].data == 'startDischargeDefault':
self.txtEMSstartDischargeDefault.SetValue(repr(sysspec['EMS_SYS_SPEC_VALUE_INT']))
def fill_mbs(self):
RSCPGuiMain.fill_mbs(self)
d = self._data_mbs
self.cbMBSProtokoll.Clear()
self._mbsSettings = {}
self.chMBSEnabled.SetValue(d['MBS_MODBUS_ENABLED'].data)
if d['MBS_MODBUS_CONNECTORS']:
for mbs in d['MBS_MODBUS_CONNECTORS']:
if mbs.name == 'MBS_MODBUS_CONNECTOR_CONTAINER':
self.txtMBSName.SetValue(mbs['MBS_MODBUS_CONNECTOR_NAME'].data)
self.txtMBSID.SetValue(repr(mbs['MBS_MODBUS_CONNECTOR_ID']))
for setup in mbs['MBS_MODBUS_CONNECTOR_SETUP']:
if setup:
if setup['MBS_MODBUS_SETUP_NAME'].data == 'Protocol':
for value in setup['MBS_MODBUS_SETUP_VALUES']:
self.cbMBSProtokoll.Append(value.data)
self.cbMBSProtokoll.SetValue(setup['MBS_MODBUS_SETUP_VALUE'].data)
elif setup['MBS_MODBUS_SETUP_NAME'].data == 'Device':
self.txtMBSDevice.SetValue(setup['MBS_MODBUS_SETUP_VALUE'].data)
elif setup['MBS_MODBUS_SETUP_NAME'].data == 'Port':
self.txtMBSPort.SetValue(setup['MBS_MODBUS_SETUP_VALUE'].data)
self._mbsSettings[setup['MBS_MODBUS_SETUP_NAME'].data] = setup['MBS_MODBUS_SETUP_VALUE']
def fill_dcdc(self):
RSCPGuiMain.fill_dcdc(self)
for d in self._data_dcdc:
index = int(d['DCDC_INDEX'])
self.gDCDC.SetCellValue(0, index, str(round(d['DCDC_I_BAT'].data, 5)) + ' A')
self.gDCDC.SetCellValue(1, index, str(round(d['DCDC_U_BAT'].data, 2)) + ' V')
self.gDCDC.SetCellValue(2, index, str(round(d['DCDC_P_BAT'].data, 2)) + ' W')
self.gDCDC.SetCellValue(3, index, str(round(d['DCDC_I_DCL'].data, 5)) + ' A')
self.gDCDC.SetCellValue(4, index, str(round(d['DCDC_U_DCL'].data, 2)) + ' V')
self.gDCDC.SetCellValue(5, index, str(round(d['DCDC_P_DCL'].data, 2)) + ' W')
self.gDCDC.SetCellValue(6, index, repr(d['DCDC_FIRMWARE_VERSION']))
self.gDCDC.SetCellValue(7, index, repr(d['DCDC_FPGA_FIRMWARE']))
self.gDCDC.SetCellValue(8, index, repr(d['DCDC_SERIAL_NUMBER']))
self.gDCDC.SetCellValue(9, index, str(repr(d['DCDC_BOARD_VERSION'])))