TagDirectWriteBitFB Function Block

Help Contents

Introduction

The TagDirectWriteBitFB Function Block writes a single bit to an address in a Data Source.

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

Functions and Function Blocks

The TagDirectWriteBitFB 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. The function block samples the state of the tag command as it executes.

To write a bit to a Data Source from an Operator Action, use the TagDirectWriteBit Function.

Syntax

The TagDirectWriteBitFB Function Block has this syntax:

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

Note: All parameters are optional.

Parameters

The TagDirectWriteBitFB Function Block has these parameters:

Parameter Type Direction Description
REQ BOOL R_EDGE Input A rising edge starts the DirectWriteBit command.
TAGNAME STRING Input The name of the tag to send the DirectWriteBit Tag Command to. For more information see TAGNAME Parameter in the remarks section.
DATAADDRESS STRING Input The "Address" of the data within the data source. See Data Address Format to understand how to set the "Address".
VALUE BOOL Input The value to write to the data source.
BUSY BOOL Output Set to TRUE while the DirectWriteBit command is in progress.
DONE BOOL Output Set to TRUE for 1 execution after the DirectWriteBit command has completed.
ERROR BOOL Output Set to TRUE if the DirectWriteBit command failed.
ERRORMSG WSTRING Output If ERROR is TRUE, the reason why the DirectWriteBit command failed.

Remarks

TAGNAME Parameter

The TAGNAME parameter is the full name of the tag that runs the DirectWriteBit Tag Command. The value of this parameter can be an absolute tag name or a relative tag name. A relative name tag name is resolved relative to the program tag that runs the function block.

The tag should be one of the types listed in the Applies To list of the DirectWriteBit Tag Command.

Timing Diagram

Once the DirectWriteBit 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.

Debug a Function Block

To monitor the state of a function block as it executes:

  1. Open the program in the Configuration Tool.
  2. Right click the program editor and select Watch Global Variables.
  3. Expand the variables on the left until the function block member variables are visible.

Use the ERROR and ERRORMSG member variables to check the tag command is executed correctly.

Examples

  1. Write a bit to an address in an Allen Bradley PLC when a digital tag changes to TRUE:
    Program MAIN
        VAR 
            (* The function block declaration *)
            WriteBitFB : TagDirectWriteBitFB;
    
            (* 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;
        END_VAR
    
        (* Run the TagDirectWriteBitFB function block 
           Note: Using Allen bradley PLC addressing to write bit 0 of outputs at slot 1 *)
        WriteBitFB( 
            REQ:=TriggerTag,
            TAGNAME:="Allen Bradley PLC Tag",
            DATAADDRESS:="O:1/0",
            VALUE:=TRUE );
    
        (* The DONE output is active for one cycle when the function block completes *)
        IF WriteBitFB.DONE THEN
    
            (* Was there an error ? *)
            IF WriteBitFB.ERROR THEN
                (* Handle any error *)
            ELSE
                (* Any additional work on successful completion *)
            END_IF;
        END_IF;
    
    END_PROGRAM
    
  2. Use a TON Function Block to toggle a bit in an Allen Bradley PLC:
    Program MAIN
        VAR 
            (* A timer on function block *)
            TimerFB : TON;
    
            (* The bit to write *)
            BitToWrite : BOOL;
    
            (* The function block to write the bit *)
            WriteBitFB : TagDirectWriteBitFB;
        END_VAR
    
        (* Run the TON block *)
        TimerFB( IN:= NOT TimerFB.Q, PT:=T#30s );
    
        (* If the timer has completed... *)
        IF TimerFB.Q THEN
    
            (* Toggle the bit *)
            BitToWrite := NOT BitToWrite;
        END_IF
    
        (* Run the TagDirectWriteBitFB function block.
           Note: The tag command is sent when the timer on FB completes *)
        WriteBitFB( 
            REQ:=TimerFB.Q,
            TAGNAME:="Allen Bradley PLC Tag",
            DATAADDRESS:="O:1/0",
            VALUE:=BitToWrite );
    
    END_PROGRAM
    

Further Information

DirectWriteBit Tag Command

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

Glossary

For the meaning of terms used in Fernhill SCADA.