A while in the past i began making a program to automate a take a look at. The factor is, my data in python was a bit restricted on the time, and the ‘last program’ was a 3000 strains, single file monstrosity. It really works, nevertheless it’s ugly. Some information about this system’s performance, it connects by serial/telnet/gpib with a card (telco PCB), and a few digital devices ( Digital Oscilloscope, sign turbines, energy meters, site visitors testers and many others), to make sure the performance of the system.Then it saves the outcomes to an excel file. It additionally has a GUI, so it is simpler for the person to grasp what is going on ( however i will not publish I’ll publish a fraction of this system right here (the remainder follows the identical logic), and that i would love some steering as a way to make it smaller, extra readable, perhaps extra simply expandable?
from threading import Thread
from tkinter.ttk import *
import serial
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import *
import re
import time
from datetime import datetime
import os
import openpyxl
from openpyxl import load_workbook
import copy
import socket
from tkinter import messagebox
import visa
#That is the place i retailer the outcomes, when the take a look at is completed, i wipe the checklist, and duplicate the second, i'd use append , however i want the leads to a sure place within the excel file in case somebody chooses to , if somebody has one other thought to attain the identical consequence, i'll gladly apply it!
resultList = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-',
'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-']
resultList2 = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-',
'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-']
#THESE 2 are the final format of the assessments
def temp_test():
ser = serial.Serial('COM3', timeout=1)
ser.baudrate = 115200
temp_command = b"!!shell sudo wf_test m_temp rn"
ser.write(temp_command)
temp_output = str(ser.learn(1000).decode())
write(temp_output)
temp_string = re.findall(r'((d+(?:.d+)?) oC)', temp_output)
temps2 = float(temp_string[0])
print(str(temps2) + ' oC')
if 'OmniBAS>' not in temp_output:
print(Temp_label.config(textual content=f"{'FAIL'}", bg='#fc2626'))
write('TestMode Not Entered')
resultList[20] = "FAIL"
return 'FAIL'
if temps2 < maxTemp:
print(Temp_label.config(textual content=f"{'PASS'}", bg='#00ff04'))
write('Temperature Take a look at PASS : ' + str(temps2) + ' oCn')
resultList[20] = "PASS"
return 'PASS'
elif temps2 > maxTemp:
print(Temp_label.config(textual content=f"{'FAIL'}", bg='#fc2626'))
write('Temperature Take a look at FAIL : ' + str(temps2) + ' oCn')
write(temp_output)
resultList[20] = "FAIL"
return 'FAIL'
elif 'Error in ioctl WF_I2C_GET_TEMP' in temp_output:
print(Temp_label.config(textual content=f"{'FAIL'}", bg='#fc2626'))
write('Temperature Take a look at FAIL: Error in ioctl WF_I2C_GET_TEMPn')
write(temp_output)
resultList[20] = "FAIL"
return 'FAIL'
def pll_test():
write('PLL Take a look at operating...n')
ser = serial.Serial('COM3', timeout=1)
ser.baudrate = 115200
pll_command = b"!!shell sudo wf_test s_pll r 1 rn"
ser.write(pll_command)
output = str(ser.learn(1000).decode())
print(output)
alarm_output = str(output)
if '[root@omnibas:~]#' not in output:
print(PLL_label.config(textual content=f"{'FAIL'}", bg='#fc2626'))
write('TestMode Not Entered')
if "pll reg=0x1 val=0x3f" in alarm_output:
print(PLL_label.config(textual content=f"{'PASS'}", bg='#00ff04'))
write('PLL Take a look at PASS : pll reg=0x1 val=0x3fn')
resultList[19] = 'PASS'
return 'PASS'
else:
print(PLL_label.config(textual content=f"{'FAIL'}", bg='#fc2626'))
write('PLL Take a look at FAILn')
write(output)
resultList[19] = "FAIL"
return 'FAIL'
def save_results():
# createFolder('C:Omnibas_10P10P_Results')
os.chdir(r'C:Omnibas_10P10P_Results')
whereas True:
strive:
wb = load_workbook('10P_Results.xlsx')
ws = wb.lively
ws.append(resultList)
wb.save('10P_Results.xlsx')
reset_list()
print(resultList)
break
besides FileNotFoundError:
wb = openpyxl.Workbook()
sheet = wb['Sheet']
ws = wb.lively
for col, val in enumerate(testList, begin=1):
sheet.cell(row=1, column=col).worth = val
ws.append(resultList)
wb.save('10P_Results.xlsx')
reset_list()
def reset_list():
international resultList
resultList.clear()
resultList = copy.deepcopy(resultList2)
def principal():
temp_test()
pll_test()
save_results()
That is this system, solely think about 50 occasions greater and uglier, how ought to i transfer from right here?