from serial import Serial
import time
ser = Serial()

def getPortName() -> str:
    return "COM"+input("Enter the number of the connected Port: ")
def getBaudRate() -> int:
    return int(input("Enter the Baudrate you are using"))
def getTimeStamp() -> str:
    current_time = time.strftime("%y%m%d%w%H%M%S")+"x" #YYMMDDwHHMMSS
    print("Getting current Time")
    return current_time

def main():
    ser.port = getPortName()
    if input("Are you using 57600 as baud rate ? (y/N)").lower() == "y":
        ser.baudrate = 57600
    else:
        ser.baudrate = getBaudRate()
    timestamp =getTimeStamp()
    print(f"Opening port {ser.port} at baudrate {ser.baudrate}")
    ser.open()
    print("Sending current time to Port")
    print(timestamp)
    ser.write(timestamp.encode())
    print("Closing Port")
    ser.close()
if __name__ == "__main__":
    main()