NJ Data Log Function Block
NJ Data Log Function Block
Version 1.0
1/19/2016
Section 1. Overview
The NJ Data Logging function block is designed to allow for easy creation of data log files in
.csv format, using data collected by the NJ CPU. This could be production data, machine fault
data, downtime data, etc. Column names are automatically written at the top of each column
when a new file is created. The data is logged to the SD card in the NJ CPU.
1. Logging of data to the SD card each time it is collected. This is useful when data
collection rate is slow (more than 1 second between data samples).
2. Logging of data stored in an array. This is useful when data is collected at a rate that
is faster than the NJ can log the data. In this case, the data is stored in an array, and
then the entire array is written to the SD card after all the data is collected.
After the data is logged to the SD card, there are several methods of retrieving the data:
1. Use the built in FTP Server functionality of the NJ to retrieve the data using an FTP
client.
2. Use the FTP Client Function Block in the NJ to push the file to an FTP Server.
3. Remove the SD card from the NJ and access from a PC.
4. Use Sysmac Studio to transfer the data from the SD card.
The function block logs a single line of text at a time to make the .csv formatted file. The
number of characters of text written includes the data from all the members of the Data Type
used to log data, along with a comma separator between each member. The total length of a
single line of text as written by the function block can be no more than 1,983 characters. Make
certain that the length of data to log in a single record does not exceed this length.
2. Open the target project in Sysmac Studio, navigate to the Programming / Function Block
section, right click, and select Paste.
3. Repeat the process for the Data Types named ‘LogDataStructure’ and
‘LogDataColumnNamesStructure’.
4. The Data Logging function block will now be part of the project, and is ready to
instantiate in the project.
Section 5. Configuring the Data to Log
The data to be logged is stored in a variable that is of type LogDataStructure. The user will
need to modify the data type LogDataStructure to meet the needs of the application. A sample
with members DateandTime, OperatorID, LogData1,LogData2, LogData3, and LogData4 was
created as an example. Any data type can be used, but in this logging application, arrays within
the LogdataStructure are not supported. All members of LogDataStructure must be simple data
types such as String, Int, Real, Boolean, Byte, etc.
There is a second data type that is used hold the column header titles. This is the
‘LogDataColumnNamesStructure’. The user must modify this to have as many members as the
LogDataStructure has members, so that each column gets a unique name.
Once the Data Types are modified, the user needs to create the 2 variables for logging. In the
example provided, the data that will be logged is named ‘DataToLog’, and is of type
‘LogDataStructure’. The column header names are stored in a variable named ‘ColumnNames’,
and is of type ‘LogDataColumnNamesStructure’. Note: the column header names can easily
be added using the Initial Value field for the ColumnNames variable.
Section 6. Using the Data Logging function block
Inputs:
Execute – Rising edge trigger to log data
Filename – a constant or variable of type String to be used as the filename, including
the entire path if folders are used. ‘Test.csv’, or ‘/MyFolder/MyFile’ are examples of the
filename. If ‘.csv’ is omitted from the end of the filename, the function block will add it
automatically. Note: the function block will write files to folders that already exist, but
will not create folders automatically.
ColumnNames – The variable containing the names of the column headers to be used
when creating a new file.
Maximum_Array_Index: When using the Array function block, this is the highest array
index number to log. 0 is always the starting array index.
Outputs:
ENO – Enable Output. Always On.
Done – On when the function block has successfully logged data.
Busy – On when function block is actively logging data.
Error – On when the function block has ended with an error.
Error_ID – numeric value of error code.
ErrorMSG – Text description of the error.