2021/07/14
How to Make an SS Recorder (3/4)
Step 3: File Output
-
3-1. Add a program
-
Add a program and write the program that creates the file
The output file looks like this
From TraceType to StartRawTime is the header, and the next line is the title row of the columns
The four columns Index, Date, ClockTime and RowTime are always required, followed by the traced variables
-
Line 0:
At the start of operation, set the reference time in SysClockStartDT and the ASCII code for "," (comma) in byteCommaLine 1:
When a memory card is inserted or at the start of operation, create the 'Rec' folder to store files
If the folder exists, the Error flag turns ON, but this can be ignoredLine 2:
On the rising edge of the record write flag (RecWrite), set the file change flag (FileChange) so the file name is changed in the following processing
Line 3:
On the falling edge of the record write flag (RecWrite), set record end (RecEnd) to instruct the write processing to finish
Line 4:
Self-holding circuit for file writing (WriteRecFile)
Writing to the file starts on the rising edge of the record write flag (RecWrite) or the file change flag (FileChange)
Line 5:
Set the header data in the write buffer (WriteBuf[]) to match the data trace file format
Use this part without changes
-
Line 6:
Write this according to the names of the variables you trace. The format is "VariableName:DataType", with variable names separated by commas
Set the variable names of the trace data as column names in the write buffer (WriteBuf[])
-
Line 7:
File names are 'Rec' + a sequence number from 0 to 199
Sequence numbers are used because continuous recording is also possible
-
Lines 8-11:
Open the file, turn ON the record data write request (WriteRequest), and if there is data in the ring buffer, execute the write (Write)
Data keeps entering the ring buffer during writing, so when writing finishes (FWrite.Done) and there are fewer than 10000 records (FileEnd=OFF), the write is executed again
-
Line 12:
ST1-9: check the number of data items in the ring buffer and write up to 100 records
ST10: read one record from the ring buffer
ST12-13: RowCnt to the Index item
ST15-16: date part of RecTime in the ring buffer to the Date item
ST17-18: time part of RecTime in the ring buffer to the Clock item
ST21-24: elapsed time in nanoseconds from the reference time (1970/1/1 0:0:0) to RecTime in the ring buffer to the RawTime item
ST26-49: write the data recorded in the ring buffer to each item (change this to match your trace data)
ST51-56: switch files when the number of written records reaches 10000
ST59: the write buffer (WriteBuf) array (bytes) is 65535, so when it exceeds 60000, FileWrite is executed once
For example:
Pos := StringToAry(INT_TO_STRING(Data.INT16), WriteBuf[Pos]) + Pos;
Change the type conversion and variable name of INT_TO_STRING(Data.INT16) to match the data type
-
Line 13:
Write the data in the write buffer (WriteBuf) to the file
Line 14:
When writing completes (FileWrite.Done) and file end (FileEnd) is ON, close the file
If record end (RecEnd), turn normal completion (OK) ON; if file end (FileEnd), turn file change (FileChange) ON
Line 15:
If any error occurs, turn error completion (NG) ON and finish
Step 4: Task Settings
-
4-1. Task settings
-
Writing large files takes time, so add a periodic task of about 20 ms to write files in a periodic task
Adjust the period between about 20 ms and 50 ms according to the amount of data traced
On the next page
On the next page, we create test data, create files and import them into Sysmac Studio data trace











