Applies To:
  • CitectSCADA 5.42

Summary:
The documentation for the TagInfo() function tells what information you can get about a variable tag, but some things that are listed in the Variable Tags Form in the Project Editor, like the tag's comment, are missing. How can I get that information? 

Solution:
TagInfo's Help lists modes 0 - 7. The other available modes are:
 

8

Format - As defined in variable tags list. See 'Format Field' below

9

Logical Unit Number - I/O device record number (for internal use)

10

Raw Type - Protocol's raw data type number for this tag

11

Bit Width - Tag's size (in bits). E.g. an INT is 16 bits

12

Unit Type - Protocol's unit type number for this tag

13

Unit Address - Tag's address after protocol DBF's template is applied

14

Unit Count - Array size. E.g. if tag's address was I1[50], the unit count would be 50

15

Record number - Tag's record number in variable.dbf - 1. E.g. the first tag would be 0.

16

Comment - As defined in variable tags list

This information has been added to the CitectSCADA help in v5.50 and above.

Note:
Many people wish to get the IODevice Number of the unit associated to a specific variable tag. To do this you can make the following function call:

IODeviceInfo(DspInfoField(0,"<tagname>","Unit"),11)

Raw Type, Bit Width, Unit Type, and Unit Address are all taken from the DBF file of the protocol that the tag uses. To find this, check the I/O Device Name for that tag. In the I/O Devices list, get the Protocol name. Open Citect\Bin\Protdir.dbf in a database editor like Excel, and find the line for that protocol. The File field on that line tells the DBF filename for that protocol. E.g. The ABTCP500 protocol's DBF file is c:\citect\bin\abslc.dbf. The protocol DBF has a line (record) for each variable tag address type. The fields on that line tell the Raw Type, Unit Type, etc. that will be returned by TagInfo()

Format Field

Although Mode 6 returns the width of the format, Mode 8 returns all format information (number of decimal places, justification, etc). However, this value requires bit operator math to decode. Mode 8 returns a long integer in the following format:

Bits 0-7

Format Width

Bits 8-15

# Decimal Places

Bit 16

Zero Padded

Bit 17

Left Justified

Bit 18

Display Engineering Units

Bit 20

Exponential (Scientific) Notation

Here is a sample function to decode them:

// Returns information about the format of the specified tag, as specified in
// the Variable Tags form's Format field.
//
// Arguments:
// sTag Tagname to use
// iMode 0 Width (including decimal and decimal places)
// 1 Number of decimal places
// 2 Zero Padded
// 3 Left Justified
// 4 Engineering Units displayed
// 5 Exponential (scientific) notation
//
// Returns: Modes 0 and 1 return an integer value. Modes 2-5 return 0 (FALSE)
// or 1 (TRUE). If Mode is invalid, -1 will be returned.
//
// For example, to return the number of decimal places in that tag, use:
// GetFormat("Motor101_SP", 1)
//
INT
FUNCTION
GetFormat(STRING sTag, INT iMode)
INT iFormat;
 iFormat = TagInfo(sTag, 8); 
 SELECT CASE iMode
CASE 0 // Width (#)
RETURN iFormat BITAND 0xff
CASE 1 // Decimals (.)
RETURN (iFormat BITAND 0xff00) / 0xff
CASE 2 // Zero Padding (0)
IF (iFormat BITAND 0x10000) = 0x10000 THEN
RETURN 1;
ELSE
RETURN 0;
END
CASE 3 // Left Justified (-)
IF (iFormat BITAND 0x20000) = 0x20000 THEN
RETURN 1;
ELSE
RETURN 0;
END
CASE 4 // EU Display (EU)
IF (iFormat BITAND 0x40000) = 0x40000 THEN
RETURN 1;
ELSE
RETURN 0;
END
CASE 5 // Exponential Notation (s)
IF (iFormat BITAND 0x100000) = 0x100000 THEN
RETURN 1;
ELSE
RETURN 0;
END
CASE ELSE // Wrong Mode
RETURN -1;
END SELECT
END
 

Keywords:
 

Attachments