import time


def cable_length(my_instrument, length=1):
    """
    Function to activate the cable length correction.
    The correction will then be active on the intrument.
    Unless tuned off, the correction will be applied to all the measurements
    collected after.

    Parameters
    ----------
    my_instrument: pyvisa.resources.usb.USBInstrument
                   Instrument instance obtained throught the Pyvisa package
    mode: str
          Options are ON or OFF.
    length: int
            Set the length of the cable to correct for. Options are 0 to 4 m

    Returns
    -------
    The function will return a print statement confirming the
    task was completed.
    """
    # Clear previous states and resets the instrument settings
    my_instrument.write('*RST; *CLS')

    # Enable the display to update itself when a change is made
    my_instrument.write(':DISP:ENAB')
    time.sleep(3)

    # Configure the instrument to automatically perform continuous
    # measurements
    my_instrument.write(':INIT:CONT')

    # * Switch the instrument triggering function to 'EXT'
    # in order to control the measurements remotely
    my_instrument.write(':TRIG:SOUR EXT')
    time.sleep(5)
    my_instrument.write(':CORR:LENG ', length)

    return print('the correction for the cable length was set to {}'
                 .format(length))