def connect(self):
        """
        Connects to a Modbus-TCP Server or a Modbus-RTU Slave with the given Parameters
        """    
        if (self.__ser is not None):
            serial = importlib.import_module("serial")
            if self.__stopbits == 0:
                self.__ser.stopbits = serial.STOPBITS_ONE
            elif self.__stopbits == 1:
                self.__ser.stopbits = serial.STOPBITS_TWO
            elif self.__stopbits == 2:
                self.__ser.stopbits = serial.STOPBITS_ONE_POINT_FIVE
            if self.__parity == 0:
                self.__ser.parity = serial.PARITY_EVEN
            elif self.__parity == 1:
                self.__ser.parity = serial.PARITY_ODD
            elif self.__parity == 2:
                self.__ser.parity = serial.PARITY_NONE

            self.__ser = serial.Serial(self.serialPort, self.__baudrate, timeout=self.__timeout, parity=self.__ser.parity, stopbits=self.__ser.stopbits, xonxoff=0, rtscts=0)
            self.__ser.writeTimeout = self.__timeout
        #print (self.ser)
        if (self.__tcpClientSocket is not None):
            self.__tcpClientSocket.settimeout(5)
            self.__tcpClientSocket.connect((self.__ipAddress, self.__port))

            self.__connected = True
            self.__thread = threading.Thread(target=self.__listen, args=())
            self.__thread.start()
Connects to a Modbus-TCP Server or a Modbus-RTU Slave with the given Parameters