FILEWRITE

FILEWRITE 1:

Data can be written into a file with this function block. For write access the file must previously have been opened in the ”FILE_OPENCREATE" or ”FILE_OPENWRITE" mode, and closed again for further processing by external programs.

VAR_INPUT

VAR_INPUT
    NETID       : T_AmsNetId;   (* ams net id *)
    HFILE       : UINT;         (* file handle *)
    BUFADDR     : DWORD;        (* buffer address for write *)
    COUNT       : UDINT;        (* count of bytes for write *)
    WRITE       : BOOL;         (* write control input *)
    TMOUT       : TIME;
END_VAR

NETID : is a string containing the AMS network identifier of the target device to which the ADS command is directed. 

HFILE : is occupied by the file handle already created by FILEOPEN.

BUFADDR : contains the address of the buffer containing the data to be written. The programmer is responsible for dimensioning the buffer such that it can accommodate WRITELEN bytes.

COUNT : contains the number of bytes to be written.

WRITE : the ADS command is triggered by a rising edge at this input.

TMOUT : specifies the time until the abortion of the function.

VAR_OUTPUT

VAR_OUTPUT
    BUSY        : BOOL;
    ERR         : BOOL;
    ERRID       : UDINT;
    COUNT_W     : UDINT;            (* count of bytes actually written *)
END_VAR

BUSY : this output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the 'Timeout' input. While Busy = TRUE, no new command will be accepted at the inputs. Please note that it is not the execution of the service but its acceptance whose time is monitored.

ERR : this output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in ‘ErrorId’. If the function block has a timeout error, 'Error' is TRUE and 'ErrorId' is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs.

ERRID : contains the instruction-specific error code of the most recently executed command. Is reset to 0 by the execution of a command at the inputs. If the error code is -1 (16#FFFF), the write operation cannot be performed because, for example, the file was not opened correctly.

COUNT_W : contains the number of bytes currently written.

 

Sample of calling the function block in FBD:

FILEWRITE 2:

In the sample, after a rising edge at ”bWriteTrig", 9 bytes of the array ”byArrTest" are written at the end of the file with handle ”61450". 

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.7.0

PC or CX (x86)

PLCSystem.Lib

TwinCAT v2.8.0

PC or CX (x86)

TcSystem.Lib

TwinCAT v2.10.0 Build >= 1301

CX (ARM)

TcSystem.Lib