def buffer_write(library, session, data):
    """Writes data to a formatted I/O write buffer synchronously.

    Corresponds to viBufWrite function of the VISA library.

    :param library: the visa library wrapped by ctypes.
    :param session: Unique logical identifier to a session.
    :param data: data to be written.
    :type data: bytes
    :return: number of written bytes, return value of the library call.
    :rtype: int, :class:`pyvisa.constants.StatusCode`
    """

    return_count = ViUInt32()
    # [ViSession, ViBuf, ViUInt32, ViPUInt32]
    ret = library.viBufWrite(session, data, len(data), byref(return_count))
    return return_count.value, ret
Writes data to a formatted I/O write buffer synchronously.

    Corresponds to viBufWrite function of the VISA library.

    :param library: the visa library wrapped by ctypes.
    :param session: Unique logical identifier to a session.
    :param data: data to be written.
    :type data: bytes
    :return: number of written bytes, return value of the library call.
    :rtype: int, :class:`pyvisa.constants.StatusCode`