FIOWrapper

FIOWrapper

Initialization

To access files via Automation Runtime, a file device must be configured in the system configuration or via the DevLink function block. To use the FIOWrap functionality, a variable must be declared of type FIOWrap_typ.

Cyclic Operation

To handle files cyclically, the FIOWrapFn_Cyclic() must be called in the CYCLIC routine of your program, once every scan, unconditionally. This function should not be called on the same FIOWrapper variable more than once per scan.

FIOWrapFn_Cyclic(FIOWrapper);

The FIOWrapper can then be used as an interface for higher level programs.

IF (OpenRecipeFile) THEN

	OpenRecipeFile := 0;

	FIOWrapper.IN.PAR.FileDevice := 'CF_User';
	FIOWrapper.IN.PAR.FileName := 'rec1.rec';
	FIOWrapper.IN.PAR.pData := ADR(Recipe);
	FIOWrapper.IN.PAR.len := SIZEOF(Recipe);

	FIOWrapper.IN.CMD.Open := 1;

END_IF

IF (SaveRecipeFile) THEN

	SaveRecipeFile := 0;

	FIOWrapper.IN.PAR.FileDevice := 'CF_User';
	FIOWrapper.IN.PAR.FileName := 'rec1.rec';
	FIOWrapper.IN.PAR.pData := ADR(Recipe);
	FIOWrapper.IN.PAR.len := SIZEOF(Recipe);

	FIOWrapper.IN.CMD.SaveAs := 1;

END_IF

IF (FIOWrapper.OUT.STAT.Done) THEN
	FIOWrapper.IN.CMD.Open := 0;
	FIOWrapper.IN.CMD.SaveAs := 0;
END_IF

No formatting is performed when opening or saving files. That is, data is not converted to or from ASCII text by this library. For opening or saving formatted text files, please use the CSVFileLib library.

Reference

FIOWrapper Data Structure

The FIOWrapper structure provides a file IO interface to higher level programs.

Inputs

The FIOWrapper inputs are divided into commands (IN.CMD) and parameters (IN.PAR). Commands are used to initiate operations, and parameters determine how the commands will be processed.

Commands
  • Open - Read data from a file.
  • SaveAs - Save data to a file.
  • AppendToFile - Append data to the end of a file.
  • Delete - Delete a file.
  • AcknowledgeError - Acknowledge any errors that occur.
Parameters
  • FileDevice - The file device to use.
  • FileName - The name of the file, including any file extension.
  • Suffix - An optional string to append to an older file’s FileName when creating a new file in MultiFile mode. If a Suffix is not provided, then a time stamp will be appended by default. This is only used when MultiFile is true.
  • pData - Starting address of the data buffer. For Open operations, data will be copied from the file to pData. For SaveAs and AppendToFile operations, data will be copied from pData to the file.
  • len - Length of the data to be copied, in bytes.
  • offset - Starting offset within the file, in bytes. For Open and SaveAs operations, data will be copied from or to the file starting at offset. For AppendToFile operations, the offset to the end of the file is obtained automatically and the offset input is ignored.
  • MaxFileSize - The maximum file size allowed during AppendToFile operations. In single file mode, if this file size would be exceeded by appending the data, then the data is not written to the file, and an error is issued. In MultiFile mode, a new file is created and no error is issued. This input is ignored during Open and SaveAs operations.
  • MultiFile - Allow multiple files to be created. When true, AppendToFile will not issue an error if the MaxFileSize would be exceeded. Instead, a new file is created with the name FileName. The original file is renamed to include the FileName and the Suffix.
  • pHeader - Address of data to be added to the top of new files if specified.
  • headerLen - Length or size of header in bytes

Outputs

The FIOWrapper outputs contain status information (OUT.STAT).

  • Busy - Operation is currently being processed.
  • Done - Operation completed successfully. Done is reset when the input command is reset.
  • Error - Error occurred during operation. Error is reset with the AcknowledgeError command.
  • ErrorID - Current error ID number.
  • ErrorString - Current error text information.
  • ErrorLevel - Current error level.
  • ReadyForCMD - The FIOWrapper is ready to accept a new command. It is equivalent to NOT(Busy OR Done OR Error).
  • NewFile - A new file was created during the last operation.
  • FileLen - The length of the file currently being operated on in bytes.

Error ID Numbers

  • 20700 - fiERR_INVALID_PATH - Invalid path.
  • 20701 - fiERR_DATA_SIZE - Data length is too small (DirRead).
  • 20702 - fiERR_NO_MORE_ENTRIES - No more file handles available.
  • 20703 - fiERR_NOT_SUPPORTED - System error.
  • 20704 - fiERR_INVALID_TYP - Invalid type.
  • 20705 - fiERR_EXIST - File already exists.
  • 20706 - fiERR_ACCESS - Access not possible with the desired mode.
  • 20707 - fiERR_MODE - Illegal mode.
  • 20708 - fiERR_FILE_NOT_FOUND - File not found. Check IN.PAR.FileName.
  • 20709 - fiERR_FILE_DEVICE - File device not found. Check IN.PAR.FileDevice.
  • 20710 - fiERR_SPACE - Not enough memory to write file.
  • 20711 - fiERR_SEEK - Invalid file offset.
  • 20712 - fiERR_FILE - File not allowed.
  • 20713 - fiERR_LESS_VIRTUAL_MEMORY - Not enough memory to write file.
  • 20714 - fiERR_COM_FILE_OPEN - System error.
  • 20715 - fiERR_COM_FILE_CLOSE - System error.
  • 20716 - fiERR_COM_FILE_READ - System error.
  • 20717 - fiERR_COM_FILE_WRITE - System error.
  • 20718 - fiERR_COM_FILE_IOCTL - System error.
  • 20719 - fiERR_DATA - Invalid parameter. Check IN.PAR.pData.
  • 20720 - fiERR_ASYNC_MANAGER - System error.
  • 20721 - fiERR_FILE_NOT_OPENED - File not opened.
  • 20722 - fiERR_INVALID_DIRECTORY - Invalid directory. Check IN.PAR.FileDevice and IN.PAR.FileName.
  • 20723 - fiERR_DIR_NOT_EXIST - Directory does not exist. Check IN.PAR.FileDevice and IN.PAR.FileName.
  • 20724 - fiERR_DIR_NOT_EMPTY - Directory is not empty.
  • 20725 - fiERR_DIR_ALREADY_EXIST - Directory already exists.
  • 20726 - fiERR_DETMEMINFO - System error.
  • 20727 - fiERR_NOT_ENOUGH_FREEMEM - Not enough memory to write file.
  • 20728 - fiERR_DIR_INVALID_HANDLE - System error.
  • 20729 - fiERR_PARAMETER - System error.
  • 20730 - fiERR_DEVICE_ALREADY_EXIST - Device already exists.
  • 20731 - fiERR_DEVICE_INVALID_HANDLE - Invalid device handle.
  • 20732 - fiERR_NETIO_IP_UNEQUAL - IP address error. Check hostname.
  • 20796 - fiERR_INIT - System error.
  • 20797 - fiERR_DEVICE_DRIVER - System error.
  • 20798 - fiERR_DEVICE_MANAGER - File device error. Check IN.PAR.FileDevice.
  • 20799 - fiERR_SYSTEM - System error.
  • 50000 - FIOWRAP_ERR_INVALIDOP - Internal error.
  • 50001 - FIOWRAP_ERR_INVALIDFILTER - Input required for IN.PAR.ItemName. Set IN.PAR.ItemName := ‘*’ to manage all files or directories.
  • 50002 - FIOWRAP_ERR_INVALIDDIR - Cannot manage in root directory. Check IN.PAR.FileDevice and IN.PAR.FileDirectory.
  • 50003 - FIOWRAP_ERR_MAXFILESIZE - Error while appending: maximum file size would be exceeded.

Error ID numbers 20700 - 20799 are passed on directly from the FileIO library. For additional information on these errors, please see the Automation Studio Online Help.