Code ready for testing.
This commit is contained in:
parent
dce5a1d459
commit
57a53ff569
@ -2,27 +2,40 @@ from src.RSIPI.rsi_client import RSIClient
|
||||
from time import sleep
|
||||
|
||||
if __name__ == "__main__":
|
||||
config_file = "RSI_EthernetConfig.xml" # Ensure this file exists in the working directory
|
||||
client = RSIClient(config_file)
|
||||
client.start()
|
||||
|
||||
# print("done")
|
||||
# config_file = "RSI_EthernetConfig.xml" # Ensure this file exists in the working directory
|
||||
# client = RSIClient(config_file)
|
||||
# client.start()
|
||||
#
|
||||
# # client.stop()
|
||||
sleep(5)
|
||||
print("rdfsfsdfsfsdfjsjfhakjshfd")
|
||||
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()
|
||||
# # print("done")
|
||||
# #
|
||||
# # # client.stop()
|
||||
# sleep(5)
|
||||
# # Dynamically update a variable
|
||||
# api.update_variable("EStr", "Tessting 123")
|
||||
# print("rdfsfsdfsfsdfjsjfhakjshfd")
|
||||
# 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()
|
||||
@ -57,12 +57,16 @@ class NetworkProcess(multiprocessing.Process):
|
||||
try:
|
||||
self.udp_socket.settimeout(5)
|
||||
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()
|
||||
|
||||
print("HERE 2")
|
||||
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)
|
||||
print(send_xml)
|
||||
print("HERE 4")
|
||||
print("Send:", send_xml)
|
||||
self.udp_socket.sendto(send_xml.encode(), self.controller_ip_and_port)
|
||||
|
||||
# ✅ If logging is active, write data to CSV
|
||||
|
||||
@ -8,6 +8,7 @@ from .rsi_graphing import RSIGraphing
|
||||
from .kuka_visualizer import KukaRSIVisualizer
|
||||
from .krl_to_csv_parser import KRLParser
|
||||
from .inject_rsi_to_krl import inject_rsi_to_krl
|
||||
import threading # (Put this at the top of the file)
|
||||
|
||||
class RSIAPI:
|
||||
"""RSI API for programmatic control, including alerts, logging, graphing, and data retrieval."""
|
||||
@ -17,10 +18,13 @@ class RSIAPI:
|
||||
self.client = RSIClient(config_file)
|
||||
self.graph_process = None # Store graphing process
|
||||
|
||||
import threading # (Put this at the top of the file)
|
||||
|
||||
def start_rsi(self):
|
||||
"""Start the RSI client."""
|
||||
self.client.start()
|
||||
return "✅ RSI started."
|
||||
"""Start the RSI client in a background thread."""
|
||||
self.thread = threading.Thread(target=self.client.start, daemon=True)
|
||||
self.thread.start()
|
||||
return "✅ RSI started in background."
|
||||
|
||||
def stop_rsi(self):
|
||||
"""Stop the RSI client."""
|
||||
|
||||
@ -3,7 +3,7 @@ import time
|
||||
import xml.etree.ElementTree as ET
|
||||
import logging
|
||||
import threading
|
||||
from .rsi_config import RSIConfig
|
||||
from rsi_config import RSIConfig
|
||||
|
||||
# ✅ Configure Logging
|
||||
LOGGING_ENABLED = True
|
||||
|
||||
@ -3,22 +3,27 @@ import xml.etree.ElementTree as ET
|
||||
class XMLGenerator:
|
||||
"""Converts send and receive variables into properly formatted XML messages."""
|
||||
|
||||
@staticmethod
|
||||
@staticmethod
|
||||
def generate_send_xml(send_variables, network_settings):
|
||||
"""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():
|
||||
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)
|
||||
for sub_key, sub_value in value.items():
|
||||
element.set(sub_key, f"{float(sub_value):.2f}")
|
||||
else: # ✅ Handle standard elements with text values
|
||||
else:
|
||||
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()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user