Code ready for testing.

This commit is contained in:
Adam 2025-04-01 21:22:09 +01:00
parent dce5a1d459
commit 57a53ff569
5 changed files with 57 additions and 31 deletions

View File

@ -2,27 +2,40 @@ from src.RSIPI.rsi_client import RSIClient
from time import sleep from time import sleep
if __name__ == "__main__": if __name__ == "__main__":
config_file = "RSI_EthernetConfig.xml" # Ensure this file exists in the working directory # config_file = "RSI_EthernetConfig.xml" # Ensure this file exists in the working directory
client = RSIClient(config_file) # client = RSIClient(config_file)
client.start() # client.start()
# print("done")
# #
# # client.stop() # # print("done")
sleep(5) # #
print("rdfsfsdfsfsdfjsjfhakjshfd") # # # client.stop()
client.update_send_variable("EStr", "Testing 123 Testing")
sleep(20)
client.stop()
# from rsi_api import RSIAPI
# from time import sleep
#
# api = RSIAPI()
# api.start_rsi()
# sleep(5) # sleep(5)
# # Dynamically update a variable # print("rdfsfsdfsfsdfjsjfhakjshfd")
# api.update_variable("EStr", "Tessting 123") # client.update_send_variable("EStr", "Testing 123 Testing")
# sleep(20)
# client.stop()
from src.RSIPI.rsi_api import RSIAPI
from time import sleep
api = RSIAPI()
api.start_rsi()
sleep(4)
# Dynamically update a variable
api.update_variable("EStr", "Tessting 123")
sleep(5)
api.stop_rsi()
# from src.RSIPI.rsi_api import RSIAPI
# from time import sleep
# def main():
# api = RSIAPI()
# response = api.start_rsi()
# sleep(50)
# print(response)
# #
# while True: #
# pass #
# # api.stop_rsi() # if __name__ == "__main__":
# main()

View File

@ -57,12 +57,16 @@ class NetworkProcess(multiprocessing.Process):
try: try:
self.udp_socket.settimeout(5) self.udp_socket.settimeout(5)
data_received, self.controller_ip_and_port = self.udp_socket.recvfrom(1024) data_received, self.controller_ip_and_port = self.udp_socket.recvfrom(1024)
print(data_received) print("Receive: ", data_received)
print("HERE 1")
message = data_received.decode() message = data_received.decode()
print("HERE 2")
self.process_received_data(message) self.process_received_data(message)
print("HERE 3")
print("Network :", self.send_variables)
send_xml = XMLGenerator.generate_send_xml(self.send_variables, self.config_parser.network_settings) send_xml = XMLGenerator.generate_send_xml(self.send_variables, self.config_parser.network_settings)
print(send_xml) print("HERE 4")
print("Send:", send_xml)
self.udp_socket.sendto(send_xml.encode(), self.controller_ip_and_port) self.udp_socket.sendto(send_xml.encode(), self.controller_ip_and_port)
# ✅ If logging is active, write data to CSV # ✅ If logging is active, write data to CSV

View File

@ -8,6 +8,7 @@ from .rsi_graphing import RSIGraphing
from .kuka_visualizer import KukaRSIVisualizer from .kuka_visualizer import KukaRSIVisualizer
from .krl_to_csv_parser import KRLParser from .krl_to_csv_parser import KRLParser
from .inject_rsi_to_krl import inject_rsi_to_krl from .inject_rsi_to_krl import inject_rsi_to_krl
import threading # (Put this at the top of the file)
class RSIAPI: class RSIAPI:
"""RSI API for programmatic control, including alerts, logging, graphing, and data retrieval.""" """RSI API for programmatic control, including alerts, logging, graphing, and data retrieval."""
@ -17,10 +18,13 @@ class RSIAPI:
self.client = RSIClient(config_file) self.client = RSIClient(config_file)
self.graph_process = None # Store graphing process self.graph_process = None # Store graphing process
import threading # (Put this at the top of the file)
def start_rsi(self): def start_rsi(self):
"""Start the RSI client.""" """Start the RSI client in a background thread."""
self.client.start() self.thread = threading.Thread(target=self.client.start, daemon=True)
return "✅ RSI started." self.thread.start()
return "✅ RSI started in background."
def stop_rsi(self): def stop_rsi(self):
"""Stop the RSI client.""" """Stop the RSI client."""

View File

@ -3,7 +3,7 @@ import time
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import logging import logging
import threading import threading
from .rsi_config import RSIConfig from rsi_config import RSIConfig
# ✅ Configure Logging # ✅ Configure Logging
LOGGING_ENABLED = True LOGGING_ENABLED = True

View File

@ -3,22 +3,27 @@ import xml.etree.ElementTree as ET
class XMLGenerator: class XMLGenerator:
"""Converts send and receive variables into properly formatted XML messages.""" """Converts send and receive variables into properly formatted XML messages."""
@staticmethod
@staticmethod @staticmethod
def generate_send_xml(send_variables, network_settings): def generate_send_xml(send_variables, network_settings):
"""Generate the send XML message dynamically based on send variables.""" """Generate the send XML message dynamically based on send variables."""
root = ET.Element("Sen", Type=network_settings["sentype"]) # ✅ Root with Type from config root = ET.Element("Sen", Type=network_settings["sentype"])
print("XML 1")
print("XML : ", send_variables)
for key, value in send_variables.items(): for key, value in send_variables.items():
if key == "FREE": if key == "FREE":
continue # explicitly skip FREE continue
if isinstance(value, dict): # ✅ Handle dictionaries as elements with attributes if isinstance(value, dict):
element = ET.SubElement(root, key) element = ET.SubElement(root, key)
for sub_key, sub_value in value.items(): for sub_key, sub_value in value.items():
element.set(sub_key, f"{float(sub_value):.2f}") element.set(sub_key, f"{float(sub_value):.2f}")
else: # ✅ Handle standard elements with text values else:
ET.SubElement(root, key).text = str(value) ET.SubElement(root, key).text = str(value)
if key == "EStr":
print(f"[DEBUG] XMLGenerator sees EStr: {value}")
print("XML 2")
return ET.tostring(root, encoding="utf-8").decode() return ET.tostring(root, encoding="utf-8").decode()
@staticmethod @staticmethod