# Buffer Commands

{% hint style="info" %}
All Buffer Commands must be prefaced by `BUF[n]` , where *n* is the index of the internal buffer. The *Binho Multi-Protocol USB Host Adapter* features just one internal buffer, therefore the only valid value for *n* at this time is *n*=0.
{% endhint %}

### CLEAR

Clears the contents of the entire 256-byte buffer.

**Parameters:**

This function takes no parameters.

**Response:**

This function returns an [ACK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#ack-response) after clearing the buffer.

**Example Usage:**

```
BUF0 CLEAR
-OK
```

### ADD

Adds a single byte of data into the buffer and increments the pointer index by +1.

Add value to buffer: `BUF[n] ADD [data]`

**Parameters:**

This function takes one parameter, *data*. This is the 8-bit unsigned integer (byte) value that will be written to the buffer. Values outside of this range will be truncated to 8 bits.

**Response:**

This function returns an [ACK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#ack-response) after adding the byte the buffer if the command succeeds. If an invalid parameter is provided, the function will return a [NAK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#nak-response).

**Example Usage:**

```
BUF0 ADD 0xAA
-OK

BUF0 READ 1
-BUF0 0xAA
```

### WRITE

Writes *n* bytes of data into the buffer, up to a maximum of 32 bytes at a time.

Add *n* bytes into the buffer beginning at *startIndex*: `BUF[n] WRITE [startIndex] [data_0] [data_1] ... [data_n]`

**Parameters:**

*startIndex* is the 8-bit integer index of the location that the first byte should be written to the buffer.

*data\_n* is the 8-bit integer (byte) that will be written to the buffer. Values outside of this range will be truncated to 8 bits.

**Response:**

This function returns an [ACK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#ack-response) after writing the data into the buffer if the command succeeds. If an invalid value is provided, the function will return a [NAK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#nak-response).

**Example Usage:**

```
BUF0 WRITE 0 10 15 20
-OK

BUF0 READ 4
-BUF0 10 15 20 0
```

### READ

Reads n bytes of data from the buffer beginning at the start of the buffer, up to a maximum of 256 bytes at a time (the entire buffer).

`BUF[n] READ [byteCount]`

**Parameters:**

*byteCount* is the 8-bit integer number of bytes to read from the buffer. Valid range is from 1 to 256 bytes.

**Response:**

This function returns a [Data Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#data-response) if the read command was successful. If an invalid value is provided, the function will return a [NAK Response](https://support.binho.io/user-guide/using-the-device/receiving-responses#nak-response).

**Example Usage:**

```
BUF0 READ 16
-BUF0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://csupport.binho.io/user-guide/ascii-interface/buffer-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
