How Can We Help?
< All Topics
Print

How to Read and Write Bit of an Integer Tag


Purpose of this article

This document aims to show how to read and write bits of an integer tag.

It is very common in PLC’s to attribute the status of equipment or commands to each bit of a tag of type integer and dword. Therefore, with this article you will learn how to access bits of a tag and use it in the scada application.

Creating a User Function

To facilitate the organization of the script, we will use a user function.

  1. Create a “User Function” and then insert the scripts below.
    The “IsBitSet” function is used for Reading and the “SetBit” function is used for writing.
  1. To read the bit of an INTEGER tag, create a Service document and add the script below:

A – Tag of type “Boolean” in which it will receive the return of the function, that is, the current value of the bit (True or False);
B – The User Function;
C – The function for reading the bit;
D – The Integer Tag being read;
E – The position of the bit being read.

Then save the service document, insert the boolean tag in a TextBox object for example.

  1. To write in the BIT of a tag of type INTEGER, add for example the script below in a button.

A– Tag of type “Integer” in which it will receive the return of the function;
B – The User Function;
C – The function for Writing the bit;
D – The Integer Tag being Write;
E – Writes the value “True” to the bit;
F – The position of the Bit being written. In this example, it is Bit 10.

Then save and run the application. Open Data Watcher and see the INTEGER tag being changed.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × five =

Table of Contents