def _write(self, dap_index, transfer_count,
               transfer_request, transfer_data):
        assert dap_index == 0  # dap index currently unsupported
        assert isinstance(transfer_count, six.integer_types)
        assert isinstance(transfer_request, six.integer_types)
        assert transfer_data is None or len(transfer_data) > 0

        # Create transfer and add to transfer list
        transfer = None
        if transfer_request & READ:
            transfer = _Transfer(self, dap_index, transfer_count,
                                 transfer_request, transfer_data)
            self._transfer_list.append(transfer)

        # Build physical packet by adding it to command
        cmd = self._crnt_cmd
        is_read = transfer_request & READ
        size_to_transfer = transfer_count
        trans_data_pos = 0
        while size_to_transfer > 0:
            if is_read:
                free = cmd.get_read_space()
            else:
                free = cmd.get_write_space()
            size = min(size_to_transfer, free)
            if transfer_data is None:
                data = None
            else:
                data = transfer_data[trans_data_pos:trans_data_pos + size]
            cmd.add(size, transfer_request, data, dap_index)
            size_to_transfer -= size
            trans_data_pos += size

            # Packet has been filled so send it
            if size == free:
                self._send_packet()
                cmd = self._crnt_cmd

            # If the request has been satisfied
            # then break from the loop
            if size_to_transfer <= 0:
                break

        if not self._deferred_transfer:
            self.flush()

        return transfer
Write one or more commands
dataset/ETHPy150Open mbedmicro/pyOCD/pyOCD/pyDAPAccess/dap_access_usb.py/DAPAccessUSB._write