Skip to content

Commit

Permalink
Fix setup.py (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
DankoCaboski authored Jun 13, 2024
2 parents 10896d3 + 66e5f48 commit dde3a98
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 79 deletions.
File renamed without changes.
64 changes: 37 additions & 27 deletions Core/Controller/OpennessController.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
myproject = None

def create_project(project_path, project_name, hardware, rb_blocks_value, gp_blocks_value):

project_dir = OpennessService.get_directory_info(project_path)

try:

Expand All @@ -24,32 +22,11 @@ def create_project(project_path, project_name, hardware, rb_blocks_value, gp_blo
print(RPA_status)

global myproject
myproject = OpennessService.create_project(mytia, project_dir, project_name)
myproject = OpennessService.create_project(mytia, project_path, project_name)

deviceName = ''
deviceMlfb = ''
for device in hardware:
deviceName = device["Name"]
deviceMlfb = device["Mlfb"]
deviceType = device["HardwareType"]

hardwareList.append(OpennessService.addHardware(deviceType, deviceName, deviceMlfb, myproject))

myproject.Save()


mysubnet = OpennessService.SetSubnetName(myproject)

ProfinetInterfaces = OpennessService.GetAllProfinetInterfaces(myproject)
print("N de interfaces PROFINET: ", len(ProfinetInterfaces))

for port in ProfinetInterfaces:
node = port.Nodes[0]
OpennessService.ConnectToSubnet(node, mysubnet)

RPA_status = "Rede PROFINET configurada com sucesso!"

myproject.Save()
if hardware != None and myproject != None:
addHardware(hardware)
wire_profinet()

if rb_blocks_value > 0 :
for device in hardware:
Expand All @@ -75,6 +52,39 @@ def create_project(project_path, project_name, hardware, rb_blocks_value, gp_blo
print(RPA_status)
return


def addHardware(hardware):
deviceName = ''
deviceMlfb = ''
for device in hardware:
deviceName = device["Name"]
deviceMlfb = device["Mlfb"]
deviceType = device["HardwareType"]

hardwareList.append(OpennessService.addHardware(deviceType, deviceName, deviceMlfb, myproject))
myproject.Save()


def wire_profinet():
ProfinetInterfaces = OpennessService.GetAllProfinetInterfaces(myproject)
print("N de interfaces PROFINET: ", len(ProfinetInterfaces))

if len(ProfinetInterfaces) > 1:
mysubnet = OpennessService.SetSubnetName(myproject)
for port in ProfinetInterfaces:
node = port.Nodes[0]
OpennessService.ConnectToSubnet(node, mysubnet)

myproject.Save()

RPA_status = "Rede PROFINET configurada com sucesso!"
print(RPA_status)

else:
RPA_status = "Número de interfaces PROFINET menor que 2"
print(RPA_status)


def open_project(project_path):
RPA_status = 'Opening project'
print(RPA_status)
Expand Down
3 changes: 0 additions & 3 deletions Core/Database/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ CREATE TABLE
description VARCHAR(500)
);

SELECT * FROM Dll_Path;

INSERT INTO Dll_Path (Tia_Version, Path) VALUES (17, 'C:\\Program Files\\Siemens\\Automation\\Portal V17\\PublicAPI\\V.17\\Siemens.Engineering.dll')
Empty file removed Core/Openness.db
Empty file.
26 changes: 9 additions & 17 deletions Core/Screen.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import sys
sys.coinit_flags = 2
import pywinauto
import os
import pywinauto
import tkinter as tk
from tkinter import filedialog, ttk, messagebox
from PIL import Image, ImageTk
import pywinauto

from repositories import UserConfig
from repositories import MlfbManagement
from repositories import UserConfig, MlfbManagement
from Controller.OpennessController import open_project, export_Block, export_data_type
from Services.OpennessService import add_DLL
import os
import Controller.OpennessController as OpennessController


favico_path = "./Assets/favico.ico"
if not os.path.exists(favico_path):
favico_path = "favico.ico"
print("File exists")

# Criando a janela principal
root = tk.Tk()
root.geometry("600x400")
# root.iconbitmap("favico.ico")
root.iconbitmap(favico_path)
root.title("RPA Tia Openness")

# Variavel no nome do projeto
Expand Down Expand Up @@ -244,18 +247,7 @@ def main_screen():
root.mainloop()
def set_version(version_select):
global selected_version
if version_select == 151:
selected_version = 151
print("151")
elif version_select == 16:
selected_version = 16
print("16")
elif version_select == 17:
selected_version = 17
print("17")
else:
print("Versão não reconhecida.")
return None
selected_version = version_select

if add_DLL(selected_version):
print(f"Versão {selected_version} configurada com sucesso.")
Expand Down
17 changes: 8 additions & 9 deletions Core/Services/OpennessService.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import re




def add_DLL(tia_Version):
try:
tuple = UserConfig.getDllPath(tia_Version)
Expand All @@ -24,8 +22,6 @@ def add_DLL(tia_Version):
import Siemens.Engineering as tia # type: ignore
import Siemens.Engineering.HW.Features as hwf # type: ignore
import Siemens.Engineering.Compiler as comp # type: ignore

print('DLL reference added successfully!')
return True

except Exception as e:
Expand All @@ -37,11 +33,14 @@ def open_tia_ui():
return tia.TiaPortal(tia.TiaPortalMode.WithUserInterface)

def create_project(tia_instance, project_dir, project_name):
proj_dir_info = get_directory_info(project_dir+"\\"+project_name)
if not proj_dir_info.Exists:
return tia_instance.Projects.Create(project_dir, project_name)
else:
return "Project already exists"
try:
proj_dir_info = get_directory_info(project_dir+"\\"+project_name)
if not proj_dir_info.Exists:
return tia_instance.Projects.Create(proj_dir_info, project_name)
else:
return "Project already exists"
except Exception as e:
print('Error creating project: ', e)

def compilate_item(to_compile):
try:
Expand Down
6 changes: 5 additions & 1 deletion Core/repositories/Connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import sqlite3
import os
from . import ValidateDb

current_path = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(current_path, "Openness.db")

def getCursor():
ValidateDb.validate_db()
conn = sqlite3.connect("Openness.db")
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
return cursor
1 change: 0 additions & 1 deletion Core/repositories/MlfbManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from . import Connection

def getMlfbByHwType(hw_type):
Connection.getCursor()
cursor = Connection.getCursor()
cursor.execute('SELECT mlfb FROM CPU_List WHERE type = ?', (hw_type,))
return cursor.fetchall()
Binary file modified Core/repositories/Openness.db
Binary file not shown.
5 changes: 1 addition & 4 deletions Core/repositories/UserConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def saveDll(Tia_Version, dll_Path):


def getDllPath(Tia_Version):

try:

cursor = Connection.getCursor()
cursor.execute('SELECT path FROM Dll_Path WHERE Tia_Version = ?', (Tia_Version,))
result = cursor.fetchone()
Expand All @@ -30,9 +30,6 @@ def getDllPath(Tia_Version):
except sqlite3.Error as e:
print("An error occurred while executing the SQL query:", e)
return None
except Exception as e:
print("An unexpected error occurred:", e)
return None


def CheckDll(Tia_Version):
Expand Down
48 changes: 33 additions & 15 deletions Core/repositories/ValidateDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,58 @@
import csv
import sqlite3

current_path = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(current_path, "Openness.db")
core_path = os.path.dirname(current_path)

def create_db():

current_path = os.path.dirname(os.path.abspath(__file__))
core_path = os.path.dirname(current_path)
ddl_path = os.path.join(core_path, "Database", "ddl.sql")
plc_List_path = os.path.join(core_path, "Database", "mlfb", "PLC_List.csv")
db_path = os.path.join(current_path, "Openness.db")

if not os.path.exists(db_path):
conexao = sqlite3.connect(db_path)
cursor = conexao.cursor()

print(ddl_path)

# Carrega o script SQL e executa
with open(ddl_path, 'r') as arquivo_sql:
script = arquivo_sql.read()
cursor.executescript(script)

conexao.commit()

with open(plc_List_path, 'r') as arquivo:
leitor_csv = csv.reader(arquivo)
for linha in leitor_csv:
print("Gravando: ", linha)
mlfb, type, descricao = linha
cursor.execute("INSERT INTO CPU_List (mlfb, type, description) VALUES (?, ?, ?)", (mlfb, type, descricao))
conexao.commit()
insert_cpu(conexao)
insert_dll(conexao)
conexao.close()


def validate_db():
current_path = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(current_path, "Openness.db")
def insert_cpu(conexao):
cursor = conexao.cursor()
plc_List_path = os.path.join(core_path, "Database", "mlfb", "PLC_List.csv")
print("Gravando dados na tabela CPU_List")
with open(plc_List_path, 'r') as arquivo:
leitor_csv = csv.reader(arquivo)
for linha in leitor_csv:
mlfb, type, descricao = linha
cursor.execute("INSERT INTO CPU_List (mlfb, type, description) VALUES (?, ?, ?)", (mlfb, type, descricao))
conexao.commit()


def insert_dll(conexao):
cursor = conexao.cursor()
print("Gravando dados na tabela Dll_Path")

for versao in range(15, 19):
if versao == 15:
path = f"C:\\Program Files\\Siemens\\Automation\\Portal V15_1\\PublicAPI\\V15.1\\Siemens.Engineering.dll"
cursor.execute("INSERT INTO Dll_Path (Tia_Version, Path) VALUES (?, ?)", (151, path))
else:
path = f"C:\\Program Files\\Siemens\\Automation\\Portal V{versao}\\PublicAPI\\V{versao}\\Siemens.Engineering.dll"
cursor.execute("INSERT INTO Dll_Path (Tia_Version, Path) VALUES (?, ?)", (versao, path))
print(path)
conexao.commit()

def validate_db():
if not os.path.exists(db_path):
create_db()

Expand Down
Empty file removed Core/repositories/database.db
Empty file.
4 changes: 2 additions & 2 deletions Core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"packages": ["pywinauto", "tkinter", "sqlite3"],
"include_files": [
# Assets
os.path.join("Assets", "favico.ico"),
"logo.png",
"favico.ico",

# Controller
os.path.join("Controller", "OpennessController.py"),
Expand Down Expand Up @@ -37,7 +37,7 @@
target = Executable(
script="Screen.py",
base=base,
icon="./favico.ico",
icon="./Assets/favico.ico",
target_name="RPA_Tia_Openness.exe"
)

Expand Down
Empty file removed Openness.db
Empty file.

0 comments on commit dde3a98

Please sign in to comment.