Skip to content

Commit

Permalink
🐍 update: Change python version
Browse files Browse the repository at this point in the history
  • Loading branch information
taffarel55 committed Mar 22, 2023
1 parent 0c19135 commit ccba4b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Dataanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DataAnalysis(object):
def __init__(self):

try:
print "Data Analysis init"
print("Data Analysis init")

except Exception as error:
raise error
Expand All @@ -31,7 +31,7 @@ def processdata(self, data, description):
timestamp = str(datetime.datetime.now())
dataforsave = "{0};{1};{2}\r".format(description, data, timestamp)
Utils.Utils.writedatafile("logs.csv", 'a', dataforsave)
print dataforsave
print(dataforsave)

except Exception as error:
raise error
23 changes: 10 additions & 13 deletions SerialLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, description):
try:
threading.Thread.__init__(self)

print "New instance logging", description
print("New instance logging"), description
self.s = None
self.baudrate = None
self.port = None
Expand Down Expand Up @@ -79,13 +79,13 @@ def connect(self, port, baudrate, timeout, rtscts=False, dsrdtr=False):
self.connState = self.s.isOpen()

if debug is True:
print "Baudrate: ", self.baudrate
print "Port: ", self.port
print "Timeout: {0} ms".format(self.timeout)
print("Baudrate: ", self.baudrate)
print("Port: ", self.port)
print("Timeout: {0} ms".format(self.timeout))

except Exception as error:
self.connState = False
print error
print(error)
raise

def disconnect(self):
Expand All @@ -111,23 +111,20 @@ def receivedata(self):

try:

data = self.s.readline()
#print data
data = self.s.readline().decode()
# print(data)
if len(data):

#if debug is True:
#print 'Data: ', data

log = '{0}'.format(re.sub('[^A-Za-z0-9]+', ' ', data))
log = re.sub('[^A-Za-z0-9]+', '', data)

if debug is True:
print log + '[' + str(datetime.datetime.now()) + ']'
print(log + '[' + str(datetime.datetime.now()) + ']')

# Data analysis class
dataanalysis.processdata(log, self.description)

except Exception as error:

self.connState = False
print "exception data: ", error
print("exception data: ", error)
raise
20 changes: 9 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
script_path = os.path.dirname(os.path.abspath(__file__))

def LoadJASON():
def LoadJSON():

try:
# Load configurations using file JSON
with open(script_path + '/config.json') as json_data_file:
data = json.load(json_data_file)

except Exception as error:
print "Fail in open JSON File"
print("Fail in open JSON File")
raise error

return data
Expand All @@ -35,13 +35,12 @@ def init_data_instances(datajson):
devices = datajson['devices']

timestamp = str(datetime.datetime.now())
message = "Start Server Logging {0} ".format(timestamp)
print message

print(f"Start Server Logging {timestamp}")

devs = list()
# Create threads for instances in datalogger
for index in range(0, len(devices)):
print "Devices:{0}".format(devices[index]['description'])
print(f"Devices:{devices[index]['description']}")
devs.append(logger(devices[index]['description']))
devs[index].run(devices[index]['serialport'], devices[index]['baudrate'], devices[index]['timeout'])
except Exception as error:
Expand All @@ -51,8 +50,8 @@ def init_data_instances(datajson):

def main():

print "############### Server Tests ########################"
data_json = LoadJASON()
print ("############### Server Tests ########################")
data_json = LoadJSON()

init_data_instances(data_json)

Expand All @@ -61,13 +60,12 @@ def main():
try:

keepAliveTimestamp = str(datetime.datetime.now())
message = "Keep Alive Datalogger {0} \n\r".format(keepAliveTimestamp)
print message
print(f"Keep Alive Datalogger {keepAliveTimestamp} \n\r")
time.sleep(10)

except Exception as error:

print "Error: ", error
print("Error: ", error)

if __name__ == "__main__":
main()

0 comments on commit ccba4b7

Please sign in to comment.