TagDirectWriteByte Function Block

Help Contents
  1. Fernhill SCADA
  2. Help
  3. Drivers
  4. Core Driver
  5. Tag Command Function Blocks
  6. TagDirectWriteByte

Introduction

The TagDirectWriteByte Function Block writes one or more bytes to an address in a data source associated with a tag.

The function block writes the data bytes by sending a DirectWriteByte tag command to the tag. The function block provides status information to:

Functions and Function Blocks

The TagDirectWriteByte 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 TagDirectWriteByte Function for use in an Operator Action.

Syntax

The TagDirectWriteByte Function Block has this syntax:

TagDirectWriteByte(
        REQ:=Expression,
        TAGNAME:=Expression,
        DATAADDRESS:=Expression,
        VALUE:=Variable-Reference,
        BUSY=>Variable-Reference,
        DONE=>Variable-Reference,
        ERROR=>Variable-Reference,
        ERRORMSG=>Variable-Reference );

Note: All parameters are optional.

Parameters

The TagDirectWriteByte Function Block has these parameters:

Parameter Type Direction Description
REQ BOOL R_EDGE Input A rising edge starts the DirectWriteByte command.
TAGNAME STRING Input The name of the PLC tag to send the DirectWriteByte command to.
DATAADDRESS STRING Input The data address within the plc.
VALUE ARRAY [] OF BYTE Input The bytes to write to the PLC.
BUSY BOOL Output Set to TRUE while the DirectWriteByte command is in progress.
DONE BOOL Output Set to TRUE for 1 execution after the DirectWriteByte command has completed.
ERROR BOOL Output Set to TRUE if the DirectWriteByte command failed.
ERRORMSG WSTRING Output If ERROR is TRUE, the reason why the DirectWriteByte command failed.

Remarks

Once the DirectWriteByte 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. The function block writing a block of data bytes to an address in a PLC.
  3. Example logic to check the status of the function block.
Program MAIN
    VAR 
        (* The function block declaration *)
        WriteByteFB : TagDirectWriteByte;

        (* 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;

        (* The data to write *)
        Data : ARRAY [0..5] OF BYTE := [1,2,3,4,5,6];
    END_VAR

    (* Call the TagDirectWriteByte function block 
       Note: Using Siemens S7 PLC addressing to write a sequence of bytes to 
             data block 01, offset 64 *)
    WriteByteFB( 
        REQ:=TriggerTag,
        TAGNAME:="Siemens S7 PLC Tag",
        DATAADDRESS:="DB01.64",
        VALUE:=DATA );

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

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

END_PROGRAM

Further Information

DirectWriteByte Tag Command

To learn about the DirectWriteByte 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.

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.

Glossary

For the meaning of terms used in Fernhill SCADA.