Ultra-Fast Whole-Structure Logging
Benefits of FileWriteVar
The FileWriteVar instruction saves an entire structure at once. No CSV or string conversion is needed, so CPU load is low and data can be saved quickly.
Suited to logging large amounts of data, waveform collection and traceability.
Overview
The FileWriteVar instruction can save structure data to an SD card
The saved file can be read on a PC with a binary editor or a custom application, but you need to write a PC program
Example
Ladder logic
Files saved with FileWriteVar are checked by opening them in a binary editor on a PC or reading them with C# etc.
Structure saved to the file (an array variable is saved)
Opening in a binary editor
Let's look at the contents of the saved file with a binary editor
The data is stored in the order of the structure: 8 bytes of date/time + 4 bytes of DINT + 4 bytes of DINT; note that the date is an incomprehensible number (the serialized date/time) and DINTs are stored in little endian order
For structures mixing several data types (INT, DINT, REAL, strings, etc.), you need to be aware of alignment
Watch out for structure alignment
Data saved with FileWriteVar is saved exactly as laid out in PLC memory. When INT, DINT, LREAL and other types are mixed, padding may be inserted according to the CPU's alignment rules.
When reading with a PC application, check the alignment rules in the PLC manual.

Reading with C#
FAQ
What is the difference between FileWriteVar and FileWrite?
FileWriteVar saves variables and structures as-is. FileWrite saves byte arrays.
Can the saved file be opened in Excel?
It is in binary format, so it cannot be opened directly. Read it with a dedicated application or C# etc.
Is FileWriteVar fast?
Yes, because no string conversion is performed. It is suited to saving large amounts of data.
How is DATE_AND_TIME saved?
As its internal 64-bit value. It must be converted to a date and time on the PC side.
