# WriteData

Use WriteData function to write data to a file or append a data string to a file on a local device or an FTP server. You can use this function to log data results and view them 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 needs to be a reference to any event with a timestamp, for example an InputPointCloud function.
Storage | Specifies whether you want to save the data file to a local device or an FTP server. The save location depends on the connected device and the Storage setting of the function.
Storage Setting | Connected Device | Save 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. If you use SD card storage, make sure that you plug in the SD card before running the job. If you configure SD card storage without plugging in an SD card, the job saves the files to the /sdcard directory of the internal flash drive.
PC | PC Note: Saving to a PC is only supported using an FTP server.
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 you select FTP Server as the 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 you select FTP Server as the Storage type.
Password | Specifies the password for 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 you select FTP Server as the 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. When saving to the PC, you can write the file to any location where you have operating system write permissions. You can enter a hardcoded path (for example, X:/, X:/Subdir), UNC path (for example, //Cognex/shared/), mapped drive (for example, M:/Subdir), or relative path (../../Subdir) into 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. If you leave this field blank, you send the file to one of the following default locations: In-Sight device: Root directory of the device. FTP Server: The default directory of the specified FTP server.
File Name | Specifies the name of the data file. Note: Follow the operating system's restrictions on the legal characters.
Data Format | Specifies the type of file. The extension is automatically 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 writes 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.