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.

The WriteData function also has a File Cleanup feature that manages the file system of a production line, ensuring that operations do not need to be halted to clear space. When enabled, the cleanup function monitors the file system each time the WriteData tool is run to maintain a specified percentage of desired free space and remove the oldest files when necessary.

To prevent the cleanup feature from removing system critical files, such as jobs stored on the vision system, make sure that the provided file path does not point to the root of the user space. If you provide the root as the file path, or the file path is not valid, the tool returns an error.

The cleanup function sorts files in the specified directory and its subdirectories based on the last time they were modified, allowing for the oldest files to be removed first when cleanup is required.

Note: The cleanup function only works as intended if the system has a valid time. Make sure that a time server is properly configured and reachable.

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 AcquireImage 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.

Emulator

In-Sight ViDi PC

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 is 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 is masked with "*" in the WriteData property sheet and the formula bar.
  • The password is 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, 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.
  • Emulator, In-Sight ViDi PC: C:/ProgramData/Cognex/In-Sight/In-Sight ViDi PC/pubfs
  • FTP Server: The default directory of the specified FTP 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.
Enable File Cleanup

Enables or disables the cleanup functionality of the tool.

Note: This option is only available when the selected storage type is Local Device. When this setting is enabled, there is an additional 30-60 µs in processing time per tool execution for checking the free space on the vision system.
Minimum Free Space

Specifies the minimum percentage of the vision system storage that is to be kept as free space.

If the storage reaches the specified limit, the cleanup functionality starts cleaning up older files to ensure that the minimum free space is retained.

Desired Free Space

Specifies the desired percentage of the vision system storage that is to be kept as free space.

When the vision system storage reaches the minimum free space limit, and the cleanup functionality starts cleaning up older files, the cleanup process stops when the vision system storage reaches the desired free space.

Note: If the tool cannot delete enough files to reach the desired free space threshold, the function returns an error after deleting what it was able to delete. There is an additional 8 ms of approximated processing time for initiating cleanup, and an additional 0.8 ms for every file deleted.

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 does not return an #ERR.