Skip to content

Commit

Permalink
v2.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo-Beci committed Jul 15, 2024
1 parent 98dfb28 commit ac5648a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
13 changes: 8 additions & 5 deletions backend/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import time
import serial
import json

# Constants
LOCALHOST_IP = "127.0.0.1"
Expand All @@ -23,9 +22,12 @@ def start_connection_controller(UDP_PORT, SERIAL_PORT, VALUES, NEWLINE, SEPARATO
if udp_socket and ser_socket:
print("Connection established")
read_serial_data(ser_socket, udp_socket, VALUES, NEWLINE, SEPARATOR, UDP_PORT)
label_connected.grid(row=18, column=1, columnspan=10)
connect_button.config(state="disabled")
disconnect_button.config(state="active")
if label_connected:
label_connected.grid(row=18, column=1, columnspan=10)
if connect_button:
connect_button.config(state="disabled")
if disconnect_button:
disconnect_button.config(state="active")
else:
disconnect()
print("Failed to establish connection, disconnecting...")
Expand All @@ -39,7 +41,7 @@ def open_stream_serial(SERIAL_PORT, BAUDRATE):
print(f"Serial port {SERIAL_PORT} is open")
return ser

except serial.SerialException as e:
except Exception as e:
print(f"Failed to open serial port {SERIAL_PORT}: {e}")

# Open a UDP JSON streaming server on the specified port
Expand Down Expand Up @@ -146,6 +148,7 @@ def send_json_to_udp(udp_socket, json_data, UDP_PORT):
# Disconnect from the serial and UDP servers
def disconnect():
try:
print("Disconnecting...")
global udp_socket, ser_socket
if udp_socket:
udp_socket.close()
Expand Down
24 changes: 15 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, config_path=None, direct_connect=False):
self.startup()

if direct_connect:
self.connect(direct=True)
self.connect_thread(direct=True)
return

# Create a new instance of Tkinter application
Expand Down Expand Up @@ -144,21 +144,27 @@ def browse_file_config_model(self):
# Update the interface with new values
self.update_interface()

def connect_thread(self):
def connect_thread(self, direct=False):
global controller_thread
# Start a new thread for the connect function
controller_thread = threading.Thread(target=self.connect, daemon=True)
controller_thread = threading.Thread(target=self.connect, args=(direct,), daemon=True)
controller_thread.start()

def connect(self, direct=False):
if not direct:
# Get the port from the textbox
self.UDP_PORT = self.textbox_udp_port.get("1.0", "end-1c")
self.SERIAL_PORT = self.textbox_serial_port.get("1.0", "end-1c")
self.VALUES = self.textbox_values.get("1.0", "end-1c").replace(" ", ",").split(",")
self.NEWLINE = self.textbox_newline.get("1.0", "end-1c")
self.SEPARATOR = self.textbox_separator.get("1.0", "end-1c")
self.BAUDRATE = self.textbox_baudrate.get("1.0", "end-1c")
if hasattr(self, 'textbox_udp_port'):
self.UDP_PORT = self.textbox_udp_port.get("1.0", "end-1c")
if hasattr(self, 'textbox_serial_port'):
self.SERIAL_PORT = self.textbox_serial_port.get("1.0", "end-1c")
if hasattr(self, 'textbox_values'):
self.VALUES = self.textbox_values.get("1.0", "end-1c").replace(" ", ",").split(",")
if hasattr(self, 'textbox_newline'):
self.NEWLINE = self.textbox_newline.get("1.0", "end-1c")
if hasattr(self, 'textbox_separator'):
self.SEPARATOR = self.textbox_separator.get("1.0", "end-1c")
if hasattr(self, 'textbox_baudrate'):
self.BAUDRATE = self.textbox_baudrate.get("1.0", "end-1c")
self.save_to_config_file() # Save the data to the CONFIG file for future reuse

try:
Expand Down

0 comments on commit ac5648a

Please sign in to comment.