using this code
# mainapp.py

import sys
from PySide6 import QtWidgets
from utils import resource_path
from MainWindow import Ui_MainWindow  # Import the generated UI
from start_up import start_up  # Import the function to initialize UI components
from comms import list_open_com_ports, send_string_to_ports, send_mdf_and_check  # Import functions from comms.py

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)  # Setup the UI from the Ui_MainWindow class

        # List to hold currently open ports
        self.open_ports = []

        # Initialize all necessary UI components and populate them
        start_up(
            self.LblStatusVersionNo, 
            self.BtnStartTest, 
            self.ComboBoxLang, 
            self.ComboBoxMaxSwl, 
            self.FldJtfDeviceModelNo, 
            self.FldJtfDeviceSerialNo, 
            self.FldJtfDeviceManufacturer, 
            self.FldJtfDeviceMaxCapacitySwl, 
            self.FldTestDataToleranceThreshold, 
            self.FldTestDataTestCycleTime, 
            self.FldTestConductedByCompany, 
            self.FldTestConductedByPlace, 
            self.FldTestDataDateOfTest,
            self.FldTestDataNextTestDue
        )

        # Connect the existing BtnInitialize to the on_initialize_clicked method
        self.BtnInitialize.clicked.connect(self.on_initialize_clicked)
        self.CbStatusPortOPen.clicked.connect(self.on_status_port_open_changed)

    def on_initialize_clicked(self):
        """Event handler for BtnInitialize click."""
        # List all open COM ports
        available_ports = list_open_com_ports()
        self.open_ports = available_ports  # Save the currently open ports

        if self.open_ports:
            print("Available COM ports:", self.open_ports)
            # Send the string "wei.zrp" to each open port and check responses
            responding_port, received_data = send_string_to_ports(self.open_ports, "wei.zrp")
            if responding_port is not None:
                self.LblStatusComPort.setText(responding_port)  # Set the label to the port name
                self.CbStatusPortOPen.setChecked(True)  # Set the checkbox to True

                # Now send 'wei.mdf' if the valid return was received
                live_data = send_mdf_and_check([responding_port], "wei.mdf")
                if live_data is not None:
                    self.LblStatusLiveData.setText(live_data)  # Set the label to the received live data
            else:
                self.LblStatusComPort.setText("--")  # Set label to "--" if no responding port
                self.CbStatusPortOPen.setChecked(False)  # Set checkbox to False if no responding port

    def on_status_port_open_changed(self):
        """Event handler for CbStatusPortOPen click."""
        if self.CbStatusPortOPen.isChecked():
            # On check, close all open ports
            for port in self.open_ports:
                try:
                    print(f"Closing port: {port}")
                    # Here you would need to close the port if you have an open connection
                    # This is just a placeholder as we are using context managers
                except Exception as e:
                    print(f"Error closing port {port}: {e}")

            self.open_ports.clear()  # Clear the list after closing ports
            self.LblStatusComPort.setText("All ports closed.")
            self.CbStatusPortOPen.setChecked(False)  # Optionally uncheck the checkbox
        else:
            # If unchecked, you might want to try reopening or updating the port list.
            self.LblStatusComPort.setText("Ports are open, no action taken.")

# Start the application
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

and
# comms.py
import serial
import serial.tools.list_ports
import time

def list_open_com_ports():
    """List all open COM ports."""
    ports = serial.tools.list_ports.comports()
    open_ports = [port.device for port in ports]
    print("Open COM ports:", open_ports)
    return open_ports

def send_string_to_ports(ports, message):
    """Send the specified string to each port and print the received data.
       Also returns the port name if the response starts with 'wei.zrp' and contains 'wei.zrp'."""
    # Append CRLF to the message
    message_with_termination = message + "\r\n"
    
    for port in ports:
        try:
            # Create a serial connection
            with serial.Serial(port, baudrate=57600, bytesize=8, parity=serial.PARITY_NONE,
                               stopbits=serial.STOPBITS_ONE, timeout=1) as ser:
                print(f"Sending data to {port}...")
                ser.write(message_with_termination.encode('utf-8'))  # Send the message as bytes

                # Wait for a response (adjust time as necessary)
                time.sleep(1)  # Delay to ensure the device has time to respond

                # Read received data, expecting it to be terminated by CRLF
                received_data = ser.read_until(b'\r\n')  # Read until CRLF
                decoded_data = received_data.decode('utf-8', errors='ignore').strip()
                
                print(f"Received from {port}: {decoded_data}")

                # Check for the expected response conditions
                if decoded_data.startswith("wei.zrp") and "wei.zrp" in decoded_data:
                    return port, decoded_data  # Return the port name and data

        except Exception as e:
            print(f"Error communicating with {port}: {e}")

    return None, None  # Return None if no port met the requirements

def send_mdf_and_check(ports, message):
    """Send 'wei.mdf' and check if the response starts with 'wei.mdf'."""
    message_with_termination = message + "\r\n"
    
    for port in ports:
        try:
            with serial.Serial(port, baudrate=57600, bytesize=8, parity=serial.PARITY_NONE,
                               stopbits=serial.STOPBITS_ONE, timeout=2) as ser:
                print(f"Sending data to {port}: {message_with_termination.strip()}")
                ser.write(message_with_termination.encode('utf-8'))  # Send the message as bytes

                # Wait for a response
                time.sleep(2)  # Adjust if necessary

                # Read received data, expecting it to be terminated by CRLF
                received_data = ser.read_until(b'\r\n')  # Read until CRLF
                decoded_data = received_data.decode('utf-8', errors='ignore').strip()
                
                print(f"Received from {port}: {decoded_data}")

                if decoded_data.startswith("wei.mdf") and "wei.mdf" in decoded_data:
                    return decoded_data  # Return the received data if it starts with wei.mdf

        except Exception as e:
            print(f"Error communicating with {port}: {e}")

    return None  # Return None if no valid response

im seeing a problem of not getting any data from the second request
def send_mdf_and_check(ports, message):

Also hitting the Initailize button again does not reconnect to com3, the used port..maybe all the same problem?

The serial coms is connected to a pi pico using micropython, code below

from machine import UART, Pin, I2C
from ssd1306 import SSD1306_I2C
import _thread
import random
import framebuf
import utime
from oled import Write, GFX, SSD1306_I2C
from oled.fonts import ubuntu_mono_15, ubuntu_mono_20

uart = UART(1, timeout=100, baudrate=56000, tx=Pin(4), rx=Pin(5), bits=8, parity=None, stop=1)
led = Pin(25, Pin.OUT)

#value inc button up
butPinValueUp=14
myButtonValueUp=Pin(butPinValueUp, Pin.IN, Pin.PULL_UP)

#value dec button down
butPinValueDown=13
myButtonValueDown=Pin(butPinValueDown, Pin.IN, Pin.PULL_UP)

#value dec button down
butPinValueReset=10
myButtonValueReset=Pin(butPinValueReset, Pin.IN, Pin.PULL_UP)

i2c = I2C(0, sda = Pin(0), scl = Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
gfx = GFX(128, 64, oled.pixel)

#initial values for data values and inc/dec values
cellValue=100000
incValue=100
randValue=9
data="awaiting input"

#fonts
write15 = Write(oled, ubuntu_mono_15)
write20 = Write(oled, ubuntu_mono_20)

oled.fill(0)
write20.text("JMS AERO AG", 7, 0)
write20.text("Data Logger", 7, 20)
write20.text("Simulator", 19, 40)
oled.show()

utime.sleep(5)

for i in range(64):
    oled.scroll(0, -2)
    oled.show()
    utime.sleep_ms(10)


#checks which button has been pressed, runs in its own thread
def checkButtons():
     
    global cellValue
    global incValue
    global oled
    global data
    
    while True:
        
        oled.show()

        oled.fill(0)
        
        oled.text(str(data),0,0)

        #write20.text(str(data),0,0)

        write20.text(str(cellValue)+" Kg",10 ,10)    
        write15.text(str(cellValue* 0.00980665)+" kN",10,26)
        write15.text(str(cellValue* 0.001)+" T",10,38)
        write15.text(str(cellValue* 0.001102317)+" US tn",10,50)

        butStateUp=myButtonValueUp.value()
    
        if butStateUp==0:
            print("Up Pressed")
            utime.sleep(.2)
            cellValue=cellValue+incValue
        
        butStateDown=myButtonValueDown.value()
    
        if butStateDown==0:
            print("Down Pressed")
            utime.sleep(.2)
            cellValue=cellValue-incValue

            
        butStateReset=myButtonValueReset.value()
    
        if butStateReset==0:
            print("Reset Pressed")
            cellValue=100000
            utime.sleep(.2)

           

        
_thread.start_new_thread(checkButtons,())


####################################################################################

#data transfer
while True:
    #global oled

    if uart.any() == True:

        data = uart.readline() 
        print(data)
        
        if data == b'<<INITIALIZE\r\n':
            led.toggle() 
            #uart.write("<<INITIALIZE\r\n")
        
        if data == b'<<CANCEL\r\n':
            led.toggle() 
            #uart.write("<<CANCEL\r\n")
            
        if data == b'<<START TEST\r\n':
            led.toggle() 
            #uart.write("<<START TEST\r\n")
        
        if data == b'wei.zrp\r\n':
            led.toggle() 
            uart.write("wei.zrp Zero Emulated\r\n")
            utime.sleep(2)

        if data == b'wei.mdf\r\n':
            led.toggle()

            gfx.fill_rect(120, 0, 8, 8, 1)

            
            from random import randrange
            randEndValue=(randrange(randValue))
            print ("wei.mdf.A:RAW:+  20617;1;ST;GS;GRO:+  " + str(cellValue) + ";NET:+  0.000; TAR:+  0.000;" + str(randEndValue) + "e\r\n")
            uart.write ("wei.mdf.A:RAW:+  20617;1;ST;GS;GRO:+  " + str(cellValue) + ";NET:+  0.000; TAR:+  0.000;" + str(randEndValue) + "e\r\n")


are there problems here that could cause a hang?