TraceSDWrite
Overview
Reads data from the ring buffer and stores the write data in the write buffer (byte array)
Once the write data is set, it is written to the SD card with the FileWrite instruction

Source
Part of TraceSDWrite (ST portion)
Data is taken from the ring buffer with RingBufGet, and if it is not a separator line (blank), it is written into the byte array WriteBuf
The write position is controlled by Pos; after converting each structure member's data to the byte array, a comma separator (0x2C) is inserted
BOOL True is converted to "1" (0x31) and False to "0" (0x30); numeric types are converted with DINT_TO_STRING etc. and then to a byte array with StringToAry
Real types are converted to strings with LrealToFormatString etc. and then to a byte array with StringToAry
When one line has been converted, the line break CrLf (0x0d, 0x0a) is inserted
Change the instructions according to the data types
If the ring buffer count is not 0, data is taken from the ring buffer again and processed the same way
If the write position Pos exceeds 60000, the buffer is considered full, and processing exits the conversion and moves to file writing
The number of lines converted per scan is adjusted with the maximum number of lines to process, RowCnt
Increasing it lengthens the scan time, but more bytes are written at once, which is expected to shorten write time
This is why it runs in a periodic task
Adjust the task period of the periodic task and the loop count of the maximum number of lines to get the best processing time
FAQ
What is TraceSDWrite?
Processing that converts data taken from a ring buffer into CSV strings and writes them to an SD card.
Why convert to a byte array first?
Writing multiple lines of data together reduces the number of SD card accesses and improves write performance.
How is BOOL data saved?
TRUE is converted to the string 1 and FALSE to the string 0 and saved as CSV data.
Why run it in a periodic task?
To manage the load of conversion and file write processing and limit the impact on the PLC scan time.
