TagDirectWriteStringFB Function Block

Help Contents


The TagDirectWriteStringFB Function Block writes a text string to an address in a data source associated with a tag.

The function block writes the text string by sending a DirectWriteString tag command to the tag. The function block provides status information to:

Functions and Function Blocks

The TagDirectWriteStringFB Function Block is intended for use in a Program Tag that runs on the Fernhill SCADA Server. A Program Tag uses a continuous execution model, where the program code runs at a fixed interval. A program uses the function block to sample the state of the tag command as it executes.

There is no equivalent TagDirectWriteStringFB Function for use in an Operator Action.


The TagDirectWriteStringFB Function Block has this syntax:

        ERRORMSG=>Variable-Reference );

Note: All parameters are optional.


The TagDirectWriteStringFB Function Block has these parameters:

Parameter Type Direction Description
REQ BOOL R_EDGE Input A rising edge starts the DirectWriteString Tag Command.
TAGNAME STRING Input The name of the tag to send the DirectWriteString Tag Command to. This can be an absolute tag name, or a relative tag name. Relative tag names are resolved relative to the full name of the host program.
DATAADDRESS STRING Input The "Address" of the data within the data source. See Data Address Format to understand how to set the "Address".
VALUE ANY_STRING Input The text string to write to the data source.
BUSY BOOL Output Set to TRUE while the DirectWriteString Tag Command is in progress.
DONE BOOL Output Set to TRUE for 1 execution after the DirectWriteString Tag Command has completed.
ERROR BOOL Output Set to TRUE if the DirectWriteString Tag Command failed.
ERRORMSG WSTRING Output If ERROR is TRUE, the reason why the DirectWriteString Tag Command failed.


Once the DirectWriteString Tag Command begins, additional requests from the input signal REQ are ignored until the tag command completes.

These timing diagrams show the relationship of the REQ, BUSY, DONE, and ERROR signals processing two requests. The first request completes with an error, the second request completes normally:

        +--------+     +-+ +------+
  REQ   |        |     | | |      |
      --+        +-----+ +-+      +------

        +------+       +------+
 BUSY   |      |       |      |
      --+      +-------+      +----------

               ++             ++
 DONE          ||             ||

ERROR          |       |
      ---------+       +-----------------

The BUSY signal is TRUE while the tag command is in progress. The DONE signal is TRUE for 1 execution after the completion of the tag command.

Example Program

The following IEC 61131-3 Program shows:

  1. A FALSE to TRUE transition of a digital data point tag used to trigger a function block.
  2. A function block writing a string value to an address in another tag.
  3. Example logic to check the status of the function block.
Program MAIN
        (* The function block declaration *)
        WriteStrFB : TagDirectWriteStringFB;

        (* The tag used to trigger the write operation
           Note: Uses a relative tag reference to 'Digital Trigger Tag' 
                 located in the same folder as this program *)
        TriggerTag AT %".Digital Trigger Tag" : BOOL;

    (* Call the TagDirectWriteStringFB function block *)
        TAGNAME:="MQTT Broker Tag",
        VALUE:="New Topic Value" );

    (* The DONE output is active for one cycle when the function block completes *)

        (* Was there an error ? *)
        IF WriteStrFB.ERROR THEN
            (* Handle any error *)
            (* Any additional work on successful completion *)


Further Information

DirectWriteString Tag Command

To learn about the DirectWriteString Tag Command.

Tag Command Function Blocks

To learn about other tag command function blocks.

IEC 61131-3 Expressions

To learn about the different types of expression to use as function parameters.

Elementary Data Types

To learn about the different types supported by Fernhill SCADA.

Common Elements

To learn about other IEC 61131-3 Common Elements.


For the meaning of terms used in Fernhill SCADA.