Applies To: |
|
Summary: |
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? |
Solution: |
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
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 sInput = ULongToStr(iVal); WHILE sInput <> "" DO // If output string length is a multiple of 4 (3 digits + comma) 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. |
Keywords: |
Related Links
Attachments