Skip to content

Commit

Permalink
Merge branch 'GitHubDragonFly-master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFern2 committed Mar 30, 2021
2 parents 7bab54f + 0336631 commit 3a35c55
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions examples/81_simple_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'''

import os.path
import platform
import threading
import pylogix
Expand Down Expand Up @@ -127,12 +128,14 @@ def main():
global sbProcessorSlot
global tbTag
global tagValue
global tagsSet
global popup_menu_tbTag
global popup_menu_tbIPAddress
global popup_menu_save_tags_list
global regularTags
global arrayTags
global tagsSet
global logHeader
global logValues

root = Tk()
root.config(background='black')
Expand All @@ -144,6 +147,8 @@ def main():
regularTags = []
arrayTags = dict()

logHeader, logValues = '', ''

changePLC = IntVar()
changePLC.set(0)

Expand Down Expand Up @@ -537,12 +542,13 @@ def startUpdateValue():
global tagsSet
global regularTags
global arrayTags
global logHeader
global logValues

'''
Call ourself to update the screen
'''

readArray = False
arrayElementCount = 0

if not connected:
Expand All @@ -560,6 +566,7 @@ def startUpdateValue():
if not tagsSet:
regularTags = []
arrayTags = dict()
logHeader = ''

if ';' in displayTag:
tags = displayTag.split(';')
Expand All @@ -574,7 +581,6 @@ def startUpdateValue():
if arrayElementCount < 2:
regularTags.append(t[:t.index('{')])
else:
readArray = True
t = t[:t.index('{')]
arrayTags.update( {t : arrayElementCount} )
except:
Expand All @@ -595,9 +601,19 @@ def startUpdateValue():
else:
regularTags.append(displayTag)

if len(regularTags) > 0:
for i in range(0, len(regularTags)):
logHeader += regularTags[i] + ', '

if len(arrayTags) > 0:
for key in arrayTags:
logHeader += key + '{' + str(arrayTags[key]) + '}, '

tagsSet = True

try:
logValues = ''

if len(regularTags) > 0:
response = comm.Read(regularTags)

Expand All @@ -606,11 +622,20 @@ def startUpdateValue():
allValues += response[i].TagName + ' : '

if (checkVarBoolDisplay.get() == 1) and (str(response[i].Value) == 'True' or str(response[i].Value) == 'False'):
if checkVarLogTagValues.get() == 1:
logValues += '1, ' if str(response[i].Value) == 'True' else '0, '

allValues += '1, ' if str(response[i].Value) == 'True' else '0, '
else:
if str(response[i].Value) == '':
if checkVarLogTagValues.get() == 1:
logValues += '{}, '

allValues += '{}, '
else:
if checkVarLogTagValues.get() == 1:
logValues += str(response[i].Value) + ', '

allValues += str(response[i].Value) + ', '

allValues += '\n'
Expand All @@ -627,8 +652,14 @@ def startUpdateValue():
for val in range(0, len(response.Value)):
newBoolArray.append(1 if str(response.Value[val]) == 'True' else 0)

if checkVarLogTagValues.get() == 1:
logValues += str(newBoolArray).replace(',', ';') + ', '

allValues += str(newBoolArray) + ', '
else:
if checkVarLogTagValues.get() == 1:
logValues += str(response.Value).replace(',', ';') + ', '

allValues += str(response.Value) + ', '

allValues += '\n'
Expand All @@ -641,21 +672,18 @@ def startUpdateValue():
return

if allValues != '':
tagValue['text'] = allValues[:-2]
tagValue['text'] = allValues[:-3]
if checkVarLogTagValues.get() == 1:
if not os.path.exists('tag_values_log.txt'):
headerAdded = False

with open('tag_values_log.txt', 'a') as log_file:
if headerAdded:
strValue = str(datetime.datetime.now()) + ', ' + allValues[:-2] + '\n'
strValue = str(datetime.datetime.now()).replace(' ', '/') + ', ' + logValues[:-2] + '\n'
log_file.write(strValue)
else:
tags = ((selectedTag.get()).replace(' ', '')).split(';')
allTags = ''

for tag in tags:
allTags += tag + ', '

# add header with 'Date / Time' and all the tags being read
header = 'Date / Time, ' + allTags[:-2] + '\n'
header = 'Date / Time, ' + logHeader[:-2] + '\n'
log_file.write(header)
headerAdded = True
else:
Expand Down

0 comments on commit 3a35c55

Please sign in to comment.