日本語 English

How to Log Fast with a Ring Buffer and FileWrite

Why use this method

The FilePuts instruction is easy to use, but the amount of data that can be written at once is limited. To save large amounts of data quickly, using the FileWrite instruction is more efficient.

Using a ring buffer allows data to be saved continuously to the SD card while limiting the impact on the PLC scan time.

Overview

Structure data is temporarily stored in the ring buffer
When writing to the SD card, data is read from the ring buffer and written
The FilePuts instruction, which writes strings to the SD card, can write 1986 bytes at a time, while the FileWrite instruction, which writes binary data, can write up to 65534 bytes at a time
However, writing characters with the FileWrite instruction requires converting strings to byte arrays, which makes the program more complex

Fast logging configuration with a ring buffer and FileWrite

Function blocks used

TraceSDWrite

TraceSDWrite function block

The ring buffer functions are also used

Ring buffer write function RingBufPut

Ring buffer read function RingBufGet

Structure for logging

Structures

Ladder program example

Primary task

VeryHardLadder1

Periodic task

VeryHardLadder2

The primary task stores data in the ring buffer
RingBufPut stores data in the ring buffer, and on the falling edge of LogFlg blank data is stored as a marker for the file separation (file change)

The periodic task reads from the ring buffer and writes to the SD card
The TraceSDWrite 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, TraceSDWrite runs and stays busy (Busy) until blank data is found; when blank data is found, it closes the file, outputs normal completion (Done) and ends

FAQ

What is the difference between FileWrite and FilePuts?

FileWrite can write binary data quickly.

Why use a ring buffer?

To prevent the scan time from increasing due to logging processing.

Which PLCs can it be used with?

It can be used with the OMRON NX series and NJ series.

Is continuous saving to the SD card possible?

Yes, data can be saved continuously via the ring buffer.

Download

Comments