# WriteData

The WriteData function is used to write data to a file or append a data string to a file on a local device or an FTP server. This function is typically used to log data results that can be viewed in a file.

Note: You can save the file to the selected Storage location while Online or Offline.

## WriteData Inputs

Parameter | Description
Data | Specifies a text string or a reference to a cell containing a text string you want to write or append to a file.
Event | Specifies the event that forces an update. This parameter must be a reference to one of the following: The Image data structure in cell A0, containing the AcquireImage function. A cell containing an Event function. A cell containing a Button function.
Storage | Specifies whether you want to save the data file to a local device or an FTP server. Depending on the connected device and the function's Storage setting, the files are saved in different location.
Storage Setting | Connected Device | Saved Location
--- | --- | ---
Local Device | In-Sight Device | In-Sight device SD card installed to the In-Sight device Note: You must use FTP software, such as FileZilla Client, to view files. For more information, see How to View Files Stored on In-Sight Device.
Emulator In-Sight ViDi PC | PC
FTP Server | Any device | Specified FTP server
Server | Specifies the server name (or IP address) of the FTP server on the network where the data file will be written. An FTP server can be an In-Sight emulator or any other device recognized as an FTP server on the network. Note: This option is enabled only when the FTP Server is the selected Storage type. If a particular port is required, you can append it to the server name. For example, the FTP server uses port 50021, enter “127.0.0.1:50021”.
User Name | Specifies the user name of the FTP server. When this field is left blank, "admin" is used. Note: This option is enabled only when the FTP Server is the selected Storage type.
Password | Specifies the password of the FTP server. The password is case-sensitive. If the FTP server does not have a password, you can leave this field blank. Note: This option is enabled only when the FTP Server is the selected Storage type. For security purposes, the entered password will be masked with "*" in the WriteData property sheet and the formula bar. The password will be saved in the job file in encrypted form.
File Path | Specifies the location where you want to save the file. To save the files to the SD card installed to the In-Sight vision system, enter sdcard in the File Path field. When saving to the PC, the file can be written to any location where you have operating system write permissions. You can enter a hardcoded path (e.g. X:/, X:/Subdir), UNC path (e.g. //Cognex/shared/), mapped drive (e.g. M:/Subdir), or relative path (../../Subdir) to this field. If the path does not exist on the In-Sight device or the PC, the function returns #ERR. If the path or FTP credentials are invalid on the FTP server, the function does not return #ERR. When this field is left blank, the file is sent to the following default location: In-Sight device: Device's root directory. Emulator, In-Sight ViDi PC: C:/ProgramData/Cognex/In-Sight/In-Sight ViDi PC/pubfs FTP Server: The specified FTP server's default directory.
File Name | Specifies the name of the data file. Note: Follow the operating system's restrictions on the legal characters.
Data Format | Specified the type of file. The extension will automatically be appended to the File Name.
0 = TXT (default) | Standard ASCII Text file format (.TXT).
1 = HTML | Standard HTML file format (.HTML).
2 = XML | Standard XML file format (.XML).
3 = CSV | Standard CSV file format (.CSV).
Append | Specifies how the data is written to the file.
0 = OFF | Overwrites the existing data in the file.
1 = ON (default) | Appends the data string to the end of the file.

## WriteData Outputs

Returns | A WriteData structure that will write the data string contained in the Data parameter to a local device or an FTP server, whenever the referenced event is triggered. Returns #ERR if any input parameters are invalid or if the file queue is full. Note: Any invalid FTP server, path or file name will not return an #ERR.