Applies To:
  • CitectSCADA 5.xx, 6.xx, 7.00
  • CitectHMI 5.xx, 6.xx, 7.00

Some PLCs support unsigned long integers (32-bit values from 0 to 4,294,967,295). If I define a variable tag with the (signed) LONG data type, CitectSCADA displays values over 2,147,483,647 as a negative number. How can I display the correct value in CitectSCADA since there is no ULONG data type? 

Version 7.00 has introduced support for the ULONG data type, so just change the data type of the tag to "ULONG" and it will be displayed correctly, however, for earlier versions you may wish to consider the following workaround:

The following Cicode function will convert an unsigned long integer into a string for display or logging in CitectSCADA. Just call the function from a text object's numeric expression and pass the LONG variable tag to it. For example:

Numeric Expression: ULongToStr(Meter1_KWH)

Basically, the way it works takes advantage of how CitectSCADA evaluates expressions. If necessary, CitectSCADA will use higher-precision data types for intermediate values in an expression, but the end result will be converted back into the normal variable tag data types. This function takes the value of the first 31 bits of the number and adds the value of the 32nd bit (if it is set), then converts it into a string instead of allowing it to be converted back into a signed long integer.

This is only useful for displaying or logging values. It will not help if you need to use the value in a mathematical expression or statement.

// Convert an unsigned long integer into a string for display in CitectSCADA 
ULongToStr(INT iVal)
IF iVal >= 0 THEN
RETURN (2147483648.0 + (iVal BITAND 2147483647)):###########;

Since numbers this large are difficult to read without commas, the following function may be used to add commas every 3 digits. It can be called in the same way as ULongToStr. For example:

Numeric Expression: ULongToCDel(Meter1_KWH)
// ULongToCDel function 
// Converts an unsigned long value to a comma-delimited value
// (a string with commas as thousands separators)
// Note: This function requires the function ULongToStr()
STRING sOutput;
STRING sInput;
	sInput = ULongToStr(iVal); 
	WHILE sInput <> "" DO 
sOutput = StrRight(sInput, 1) + sOutput;
sInput = StrLeft(sInput, StrLength(sInput) - 1);
		// If output string length is a multiple of 4 (3 digits + comma) 
// and Input string still has more chars then...
IF ((StrLength(sOutput) + 1) MOD 4 = 0) AND (StrLength(sInput) >= 1) THEN
sOutput = "," + sOutput; // The comma could be replaced by a period if desired
	RETURN sOutput;
Note: It is also possible to display 64-bit unsigned long long integers in Citect, but a different calculation method is required because of the higher precision. See Citect Toolbox item Q1317.