-

Y_RW_Write_CSV_File

Image

This function block will format and write a CSV (ASCII) file to the controllers flash or ram disk. The original data is a user specified structure. This function block requires customization to accommodate application specific data requirements. Any variety of rows and columns and datatypes can be customized.

Parameters

* Parameter Data Type Description Default
VAR_IN_OUT
B Data Yt_RW_MyDataStruct A user customized data structure containing the information (possibly still in binary format) to be written to a CSV file.
VAR_INPUT
B Execute BOOL Upon the rising edge, this function block will prepare to engage the RampIn cam profile at the master position specified in the BlendData structure. FALSE
V FileName STRING The file to be written. See path example in Memory area available for user files in ic92xx. STRING#''
V Append BOOL This flag indicates whether to delete an existing file and create new data, or add to an existing file. If Append=TRUE, data will be appended. Data.MaxRecords must be set by the user to indicate the number of rows in MyDataStruct to append. FALSE
V Separator BYTE The byte value of the ASCII character to be used for separating values of data on a line. If unconnected, the comma (BYTE#44) will be used. BYTE#44
V Version UDINT Optional. If used, this function block has the ability to be customized to select between multiple output formats. UDINT#0
V BufferSize UDINT Specifies the number of bytes in the file to process at one time. BufferSize can be adjusted up or down if necessary to accommodate various file sizes and will depend upon the CYCLIC task in which the Read_CSV_File function block is executed. Maximum value is 512, above this value, no error will be generated, but the BufferSize will be overwritten to 512 bytes internally. UDINT#512
VAR_OUTPUT
B Done BOOL Set high when the axis or group is synchronized with the axis or group it is commanded to follow. Synchronized means that the two are position locked, any transitional period required to achieve synchronization has been completed.
B Busy BOOL Set high upon the rising edge of the Execute input, and reset when Done, CommandAborted, or Error is true. In the case of a function block with an Enable input, a Busy output indicates the function is operating, but not ready to provide Valid information. (No Error)
B Error BOOL Set high if an error has occurred during the execution of the function block. This output is cleared when 'Execute' or 'Enable' goes low.
E ErrorID UINT If Error is true, this output provides the Error ID. This output is reset when 'Execute' or 'Enable' goes low.
V ErrorRow INT If Error is true and pertains to a problem with the source data, this value will indicate the location of processing when the error occurred.
V ErrorCol INT If Error is true and pertains to a problem with the source data, this value will indicate the location of processing when the error occurred.

Notes

Error Description:

See the Function Block ErrorID List.

Example 1

Y_RW_Write_CSV_File must be customized to accommodate your data. Two locations requiring customization are identified in the function block body by several rows of comments indicating the need to customize. To effectively use this function, follow the steps given below:

1) Copy & paste the Yt_RW_MyDataStruct and associated datatypes into your project, and rename them to avoid conflict with Yt_RW_MyDataStruct in the datatypes file of the Y_FileRW_Toolbox.



2) Modify the definition shown above such that it represents the data to be written.

3) Initialize the data required for "MyDataStruct" as shown below. Most importantly, set Columns and MaxRecords. MaxRecords indicates how may lines of data are to be written to the file. In the case of Append mode =TRUE, set MaxRecords to the number of lines from the MyDataStruct to be appendedexe. Appending always starts from the first line (array element 0) of the structure and adds data to the end of the file. It is not necessary to initialize (clear) the other data elements beyond MaxRecords that may be from a previous use.

Image

4) Copy & paste the Y_RW_Write_CSV_File function block into your main project so it can be customized. This will allow you to retain the original function in the template for future reference. Rename the function to avoid name conflict with Y_RW_Write_CSV_File in the Toolbox. To copy & paste the function block, open a second copy of the software, and open the File_Read_Write toolbox as a project. From the second software instance, copy & paste the function block into your project.


Customizing the code in the function block

5) To customize the function block, go to the variables grid and rename the datatype used as the VAR_IN_OUT to the datatype you customized in step 2 above.

6) Locate the comments near the middle of the Y_RW_Write_CSV_File function indicating the area to be customized. Modify the lines that convert binary data from the MyDataStruct structure to STRING data for the file.

Image

Image



Append to a file:


To append data to the file written above,

Image

Image


The appended data can be seen if the file is read.

Image



Customizing for file versioning

The function has the capability to write multiple versions of the same structure. For example, a portion of the data from the structure can be written to one file, and a different set of data can be written to another file.

To use file versioning, follow the steps below:

1) Set the 'Version' function block input to a unique value (Non zero).

2) Customize the DataType to reflect the most current data specification.



3) Customize the Y_RW_Write_CSV_File function block to determine if a specific version of the file should be written.



4) Customize the Y_RW_Write_CSV_File function block to write multiple versions.




 


This help information is valid for iCube Engineer Online Help 2025.6

Copyright © 2025 YASKAWA EUROPE GmbH and © 2025 YASKAWA America, Inc.