<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _send_command(self, command, immediate=False, timeout=1.0, check_echo=None):
 """ Send a single command to the drive after sanitizing it. Takes a single given `command`, sanitizes it (strips out comments, extra whitespace, and newlines), sends the command to the drive, and returns the sanitized command. The validity of the command is **NOT** checked. Parameters command : str The command to send to the Gemini drive. immediate : bool, optional Whether to make it so the command is executed immediately or not. timeout : number, optional Optional timeout in seconds to use to get the command right when we are doing echo checking. A negative value or ``None`` indicates that the an infinite timeout should be used. check_echo : bool or None, optional Whether the echoing of the command as it is being written to the drive should be used to correct mistakes in what the drive is seeing, or whether the default set when the instance of this class was created should be used (``None``). Returns ------- sanitized_command : str The sanitized command that was sent to the drive. """

        # Use the default echo checking if None was given.
        if check_echo is None:
            check_echo = self._check_echo

        # Convert to bytes and then strip comments, whitespace, and
        # newlines.
        if sys.hexversion >= 0x03000000:
            c = bytes(command, encoding='ASCII')
        else:
            c = command
        c = c.split(b';')[0].strip()

        # If the command is supposed to be immediate, insure that it
        # starts with an '!'.
        if immediate and not c.startswith(b'!'):
            c = b'!' + c

        # Read out any junk on the serial port before we start.
        self._ser.read(self._ser.inWaiting())

        # The command needs to be written a character at a time with
        # pauses between them to make sure nothing gets lost or
        # corrupted. This is a simple loop if we are not checking the
        # echo. If we are, it is more complicated.
        if not check_echo:
            for i in range(0, len(c)):
                self._ser.write(bytes([c[i]]))
                time.sleep(0.01)
        else:
            # Infinite timeouts need to be converted to None. Finite
            # ones need to be checked to make sure they are not too big,
            # which is threading.TIMEOUT_MAX on Python 3.x and not
            # specified on Python 2.x (lets use a week).
            if timeout is None or timeout <= 0:
                timeout = None
            else:
                if sys.hexversion >= 0x03000000:
                    maxtimeout = threading.TIMEOUT_MAX
                else:
                    maxtimeout = 7*24*3600
                timeout = min(timeout, maxtimeout)

            # A timer will be made that takes timeout to finish. Then,
            # it is a matter of checking whether it is alive or not to
            # know whether the timeout was exceeded or not. Then, the
            # timer is started.
            tm = threading.Timer(timeout, lambda : None)
            tm.start()

            # Each character needs to be written one by one while the
            # echo is collected. If any mistakes occur, they need to be
            # corrected with backspaces b'\x08'. The echo starts out
            # empty. We go until either the echo is identical to the
            # command or the timeout is exceeded.
            echo = b''
            while c != echo and tm.is_alive():
                # If there are no mistakes, then echo will be the
                # beginning of c meaning the next character can be
                # written. Otherwise, there is a mistake and a backspace
                # needs to be written.
                if c.startswith(echo):
                    self._ser.write(bytes([c[len(echo)]]))
                else:
                    self._ser.write(b'\x08')

                # Pause for a bit to make sure nothing gets lost. Then
                # read the drive's output add it to the echo.
                time.sleep(0.01)
                echo += self._ser.read(self._ser.inWaiting())

                # All backspaces in echo need to be processed. Each
                # backspace deletes itself and the character before it
                # (if any).
                while b'\x08' in echo:
                    index = echo.index(b'\x08')
                    if index == 0:
                        echo = echo[1:]
                    else:
                        echo = echo[0:(index-1)] + echo[(index+1):]

            # Turn off the timer in the case that it is still running
            # (command completely written before timeout).
            tm.cancel()

        # Write the carriage return to enter the command and then return
        # the sanitized command.
        self._ser.write(b'\r')
        if sys.hexversion >= 0x03000000:
            return c.decode(errors='replace')
        else:
            return c