# CSV Export

This function block collects incoming data columns over time and saves them as a CSV file when requested. Use it to build simple data logs (measurements, counters, labels) and export them for analysis or archiving.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

* `Folder Path` Folder where the CSV file will be saved (uses current folder if not provided)
* `File Name` File name to use for the exported CSV (timestamped default if not provided)
* `Start Logging` Boolean trigger to start appending incoming data into the internal log buffer
* `Export File` Boolean trigger to write accumulated log data into the CSV file
* `Data_1` ... `Data_10` Generic data columns that will be stored (only connected columns are logged)

## 📤 Outputs <a href="#outputs" id="outputs"></a>

* This function block does not produce any outputs.

## 🕹️ Controls <a href="#controls" id="controls"></a>

* `Header fields` Ten text fields where you can provide human-friendly column names for the corresponding `Data_1` ... `Data_10` inputs. Leave fields empty to use the default `Data_n` labels.
* `Start Logging` input Used to enable logging of incoming values into the internal buffer.
* `Export File` input Used to flush the buffered rows into a CSV file on disk.

## 🎯 Features <a href="#features" id="features"></a>

* Automatic timestamp per row (time is added as the first column).
* Flexible columns: only connected `Data_n` inputs are included in the CSV.
* Header management: if you change header fields, existing CSV header row is updated automatically (if the file already exists).
* Buffered logging: rows are stored internally while `Start Logging` is active and written out only when `Export File` is triggered.
* Safe write behavior: warnings and errors are shown in the UI if the file is open elsewhere or write fails.

## 📝 How to use <a href="#usage" id="usage"></a>

1. Set destination using `Folder Path` and `File Name` inputs (optional).
2. Provide readable column names in the `Header fields` for any `Data_n` sockets you will connect.
3. Connect the data sources to the corresponding `Data_1` ... `Data_10` inputs (use only the inputs you need).
4. Drive `Start Logging` with a boolean signal (for example via a `Logic Input` block) to begin buffering rows.
5. When ready, activate the `Export File` input to save buffered rows to disk. The block will add or update the CSV header automatically.

## 📊 Behavior <a href="#evaluation" id="evaluation"></a>

* While `Start Logging` is active the block captures the current timestamp and the values of all connected data sockets into an internal list.
* When `Export File` becomes true the block writes the accumulated rows to the CSV file at `Folder Path` + `File Name`. After successful export the internal buffer is cleared.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Use `Date-Time` or `Date-Time List` blocks to build meaningful file names or to feed extra time-related columns in addition to the automatic timestamp.
* Use `Logic Input` to manually control `Start Logging` and `Export File` from the UI.
* When logging numeric measurements, use `Number Input` or math blocks (like `Add`, `Subtract`) upstream to prepare values before connecting to the `Data_n` inputs.
* For string labels or IDs, use `String Input` or `String Merge` to combine text fields before sending to a `Data_n` input.
* To export image-related metadata (e.g., frame count, detection numbers), connect relevant analysis blocks such as `Object Detection`, `Mask Detection`, or `Find Object` into the generic `Data_n` inputs.
* If you want to save images alongside numeric logs, use `Image Logger` or `Image Write` in parallel and keep CSV for numeric/textual metadata only.
* Use `CSV Export` together with `Scope` to visualize numeric streams and then save the data once you verify events of interest.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* File not saved / permission error: make sure the CSV file is not open in another program and that you have write permission for the selected folder. Run the application with sufficient privileges if needed.
* No data exported: ensure you have activated `Start Logging` at least once so that the internal buffer contains rows before triggering `Export File`. The block will warn if there is no stored data when export is requested.
* Wrong columns in CSV: confirm which `Data_n` sockets are connected and adjust the `Header fields` text boxes. The block only includes connected inputs and updates the header when you change header text.


---

# 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://docs.augelab.com/function-blocks/input-output/outputs-exports/csv-export.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.
