def create_chunks(ascdata, max_bytes_in_barcode):
    """Chunk ascdata into a list of blocks with size max_bytes_in_barcode or less.
    Only specific ASCII characters are allowed in ascdata so we don't worry about Unicode.
    Each block begins with ^<sequence number><space> (1-based).
    This allows to easily put them back together in the correct order."""
    # Slicing ascdata reduces processing time to about 5% compared to handling each char separately
    chunks = []
    chunk_idx = 0
    while chunk_idx < len(ascdata):
        chunkdata = "^" + str(len(chunks)+1) + " "
        charnum = max_bytes_in_barcode - len(chunkdata)
        chunks.append(chunkdata + ascdata[chunk_idx:chunk_idx+charnum])
        chunk_idx += charnum
    return chunks