# Data logger

## Data Logger คืออะไร&#x20;

&#x20;          data logger เป็นอุปกรณ์สำหรับบันทึกข้อมูลเซนเซอร์พร้อมกับค่าเวลาจริงที่รับค่าจากเซนเซอร์ หลักการทำงานของ data logger จะเป็นการรับค่าสัญญาณ analog จากเซนเซอร์มาแปลงเป็นข้อมูล digital แล้วเก็บเป็นชุดข้อมูลที่ประกอบด้วย ค่าเซนเซอร์ และเวลาที่ได้รับค่าเซนเซอร์ มาเก็บไว้ในหน่วยความจำ สำหรับ data logger จะมีทั้งเป็นอุปกรณ์สำเร็จรูปที่มาพร้อมกับเซนเซอร์ โดยสามารถวัดค่าเซนเซอร์และเก็บข้อมูลได้ในตัว หรือเราสามารถสร้างdata logger ได้โดยใช้บอร์ดสมองกลฝั่งตัวในการเขียนโปรแกรมให้อ่านค่าเซนเซอร์และเวลา บันทึกลงไฟล์ต่าง ๆ เช่น .txt .csv .json เป็นต้น&#x20;

## ประโยชน์ของ Data Logger&#x20;

เครื่องคอมพิวเตอร์ หรือ บอร์ดสมองกลฝั่งตัว (Embedded boards) สามารถอ่านข้อมูลจาก data logger เพื่อนำไปใช้งานต่าง ๆ เช่น การแสดงกราฟข้อมูลเซนเซอร์ในแต่ละช่วงเวลา หรือการนำข้อมูลไปวิเคราะห์เปรียบเทียบข้อมูลแต่ละช่วงเวลา( time series) เป็นต้น &#x20;

## Data logger ใน C++

\
ไลบารี่สำหรับเขียนและอ่านไฟล์ของ c++ โดยกำหนดประเภทสำหรับการทำงานเป็นดังนี้

| Class    | Description                             |
| -------- | --------------------------------------- |
| ifstream | ใช้สำหรับอ่านข้อมูลจากไฟล์              |
| ofstream | ใช้สำหรับสร้างไฟล์ และเขียนข้อมูลลงไฟล์ |
| fstream  | ใช้สำหรับเขียนและอ่านไฟล์               |

สำหรับการเริ่มต้นใช้งานให้ทำการ include ไลบารี่ fstream  &#x20;

```cpp
#include <fstream>


Update: May 2023
Author: Soontree Jaikhong (AIC-Researcher)
Author: Thanaluk Pranekunakol (AIC-Researcher)
```


---

# 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.aic-eec.com/c-c++-for-embedded-programming/data-logger.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.
