<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rtt_write(self, buffer_index, data):
 """Writes data to the RTT buffer. This method will write at most len(data) bytes to the specified RTT buffer. Args: self (JLink):
 the ``JLink`` instance buffer_index (int):
 the index of the RTT buffer to write to data (list):
 the list of bytes to write to the RTT buffer Returns: The number of bytes successfully written to the RTT buffer. Raises: JLinkRTTException if the underlying JLINK_RTTERMINAL_Write call fails. """

        buf_size = len(data)
        buf = (ctypes.c_ubyte * buf_size)(*bytearray(data))
        bytes_written = self._dll.JLINK_RTTERMINAL_Write(buffer_index, buf, buf_size)

        if bytes_written < 0:
            raise errors.JLinkRTTException(bytes_written)

        return bytes_written