# WriteData

Use WriteData function Functions are tools that are available in Spreadsheet for processing and analyzing acquisitions or other results. You can add functions to your Spreadsheet job to create tool chains and produce results for specific applications. 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

The WriteData function has the following syntax:

WriteData(Data, Event, Storage, Server, User Name, Password, Block Execution, Timeout, File Path, File Name, Append, Data Format, File Retention Enabled, Minimum Free Space, Desired Free Space)

See the table for a description of the available parameters.

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 refer 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 View Files Stored on the In-Sight Vision System.
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 A job is a user-configured program in In-Sight 3D Spreadsheet consisting of functions and designed for specific applications. You can create and edit jobs using the In-Sight 3D Spreadsheet interface, and load them on a vision system for deployment in a live environment. 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 3D 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.