def get_port_information(vips, matching_no):
    """
    Get information on what sampling ports are used in a match, and check that
    everything is set up correctly.
    Return the number of the first port, and a boolean indicating if the second port is used.
    """
    sample_port_1 = int(vips.getValue(f'Template matching {matching_no} - first sampling port'))
    use_port_2 = vips.getValue(f'Template matching {matching_no} - match on two ports')
    sample_port_2 = sample_port_1 + 1 if use_port_2 else 0

    if sample_port_2 > 8:
        raise ValueError(f'Cannot perform template matching on two ports if the first is port 8!')

    # Matching can only happen on ports with sampling activated
    if sample_port_1 not in vips.sampling_ports or sample_port_2 not in [0, *vips.sampling_ports]:
        raise ValueError(f'Template matching {matching_no}: '
                         f'Sampling needs to be enabled on the ports set as sampling ports!')

    return sample_port_1, use_port_2