How to Save PLC Event Logs as CSV Files
Benefits of event-based CSV saving
- Saves only changed data
- Keeps file sizes small
- Opens directly in Excel
- Contents can be checked without a host application
- Makes troubleshooting easier
Differences between CSV and binary saving
| Item | CSV | Binary |
|---|---|---|
| Readability | High | Low |
| File size | Large | Small |
| Speed | Slow | Fast |
| Analysis | Easy | Dedicated tool required |
How Event Log Saving Works
Data is recorded when a memory value changes
The method of writing to the SD card is the same as "Logging with a ring buffer and byte arrays"

Symbols
EventLogSDWriteCSV
The processing is almost the same as TraceSDWrite
Structure for event logs

Primary task processing

Periodic task

How EventLogSDWriteCSV works
In the primary task, when the value of a monitored memory changes, RingFilePut adds the time, variable and value to the buffer
For bit information, changes are detected by comparing with the previous value using XOR to monitor OFF→ON and ON→OFF
For numbers, the current value is subtracted from the previous value to check whether it exceeds the change range (rangeDInt)
The periodic task reads from the ring buffer and writes to the SD card
The EventLogSDWriteCSV FB, which converts to byte arrays and writes to the SD card, takes time, so adjust with a task period of 10 ms or more
If there is data in the ring buffer, EventLogSDWriteCSV is executed to write it to the SD card
FAQ
Can the CSV file be opened in Excel?
Yes. The saved CSV file can be viewed in Excel or a text editor.
What is the difference between event logs and periodic logs?
Event logs save only when values change, which reduces data volume.
Is CSV saving slower than binary saving?
CSV saving generally has a higher processing load because string conversion is needed.
Why use a ring buffer?
To prevent data loss even when events are concentrated in a short time.
