# 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.
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, one of the following: 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/SFTP server.
Storage Setting | Connected Device | Save Location
--- | --- | ---
Local Device | In-Sight Device | 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.
In-Sight Emulator | Host PC
PC | PC Note: Saving to a PC is only supported using an FTP/SFTP server.
FTP Server | Any device | Specified FTP server
SFTP Server | Any device | Specified SFTP server
Server | Specifies the server name (or IP address) on the network where the image file is written. Note: This option is enabled only when you select FTP Server or SFTP Server as the Storage type. When a particular port is required, you can append it to the server name. For example, the FTP/SFTP server uses port 50021, and the IP address of the server is 192.168.0.12, enter 192.168.0.12:50021.
User Name | Specifies a valid user name for the FTP/SFTP server. When this field is left blank, admin is used. Note: This option is enabled only when you select FTP Server or SFTP Server as the Storage type.
Password | Specifies the password for the FTP or SFTP server. The password is case-sensitive. If the FTP or SFTP server does not have a password, you can leave this field blank. Note: This option is enabled only when you select FTP Server or SFTP Server as the Storage type. For security purposes, the entered password is masked with "*" in the WriteData property sheet and the formula bar. The password is saved in the job file in encrypted form.
Block Execution | Specifies whether to block job execution until file transfer is complete. If checked, the In-Sight vision system only processes the next cell in the chain after the writing or transferring of the image is completed.
Timeout | Specifies the time in milliseconds to block the execution. If the time to complete writing data to file or remote server exceeds this value, the tool returns #ERR to inform the job that the timeout was exceeded. Note: This option is only available if you enable the Block Execution parameter.
- File Path | Specifies the location where you want to save the file. When connected to an In-Sight emulator, and saving to the PC, you can write the file to any location where you have operating system write permissions. You can enter the following file path types to this field:
  Path | Example
  hardcoded | X:/, X:/Subdir
  UNC | //Cognex/shared/
  mapped drive | M:/Subdir
  relative | ../../Subdir
If you set a non-empty, non-absolute path, the file path is relative to the default directory. For example, relative/file.txt resolves to /home/user/relative/file.txt. If the path does not exist on the In-Sight vision system or the emulator host PC, the tool creates the folder. If the path or FTP/SFTP credentials are invalid on the FTP/SFTP server, the tool does not return #ERR. Tip: Depending on your FTP/SFTP server, a valid file path can contain forward slashes or back slashes. Make sure to use a file path convention that your file server accepts. If you leave this field blank, you send the file to one of the following default locations: Local device: Default directory of the device. In-Sight emulator: %USERPROFILE%\Documents\In-Sight Spreadsheet\In-Sight Emulator FTP Server: The default directory of the specified FTP server. SFTP Server: The default directory of the specified SFTP server.
File Name | Specifies the name of the data file. Note: Follow the restrictions of the operating system 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.

Outputs

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