Promotic

TransformValue - method of the Pm object

Description:
Transformation of the value.
Syntax:
Variant TransformValue(Variant vValue, Long nType)
Parameters:
vValue(Variant) Value that is transformed
nType(Long) Type of transformation
1 - 12 -> 21 - Swaps 1st<->2nd byte in the value of the Integer type (see Example1). It is so-called 2-byte value transfomation from Little-endian to Big-endian (or backwards).
2 - 1234 -> 4321 - Swaps 1st<->4th byte and 2nd<->3rd byte in the value of the Long type. It is so-called 4-byte value transfomation from Little-endian to Big-endian (or backwards).
20 - Long -> BCD - Transforms a value of the Long type (range 0-99999999) to the value of the Long type in BCD format (see Example2).
21 - BCD -> Long - Transforms a value of the Long type in BCD format to the value of the Long type.
40 - ElementArray -> Array - Transforming an array where the array items are of a real elementary data type (i.e. instead of being Variant type) into the standard (VBScript) form, where each array item is represented by a Variant type value of specified subtype. This kind of transformation may be handy, for example, if the array is gained from the communication or from a DLL library function.
41 - Array -> ElementArray - Transforming the standard VBScript array, where the array items are of the Variant type, into the array where each array item is represented by the same elementary data type (i.e. instead of being Variant type). This kind of transformation may be handy, for example, if the array is being sent into a communication (for OPC see Data vector transfer) or into a DLL library function.
50 - Matrix -> TranspMatrix - In a value of the array type (2-dimensional array) the mutual counterchange of columns and rows is performed (transposed array).
100 - Simatic -> Single - Transforms a value of the Single type from the real number format PLC SIMATIC S5.
101 - Single -> Simatic - Transforms a value of the Single type into the real number format PLC SIMATIC S5.
120 - Real -> "99x9" - The value will be converted to string, where for real numbers (Single, Double or Date) the decimal separator will be used according to the OS Windows settings.
This and the following two transformations are suitable, for example, for saving the values into text files, see Data sharing by files.
121 - Real -> "99.9" - The value will be converted to string, where for real numbers (Single, Double or Date) the period (".") will be used as decimal separator regardles to OS Windows settings.
122 - Real -> "99,9" - The value will be converted to string, where for real numbers (Single, Double or Date) the comma character (",") will be used as decimal separator regardles to OS Windows settings.
200 - Value -> Array of Boolean - Creates the binary array (Array) with values of the Boolean type (see Example3). Each value of the array has one bit value of the vValue parameter. The vValue parameter can be of:
- Byte type: there are 8 values in the array (opposite to the transformation type 221)
- Integer type: there are 16 values in the array (opposite to the transformation type 222)
- Long type: there are 32 values in the array (opposite to the transformation type 223)
- Single type: there are 32 values in the array (opposite to the transformation type 224)
- Double type: there are 64 values in the array (opposite to the transformation type 225)
201 - Value -> Array of Byte - Creates the binary array (Array) with values of the Byte type. Each value of the array has one byte value of the vValue parameter. The vValue parameter can be of:
- Byte type: there is 1 value in the array (opposite to the transformation type 221)
- Integer type: there are 2 values in the array (opposite to the transformation type 222)
- Long type: there are 4 values in the array (opposite to the transformation type 223)
- Single type: there are 4 values in the array (opposite to the transformation type 224)
- Double type: there are 8 values in the array (opposite to the transformation type 225)
202 - Value -> Array of Integer - Creates the binary array (Array) with values of the Integer type. Each value of the array has two bytes value of the vValue parameter. The vValue parameter can be of:
- Integer type: there is 1 value in the array (opposite to the transformation type 222)
- Long type: there are 2 values in the array (opposite to the transformation type 223)
- Single type: there are 2 values in the array (opposite to the transformation type 224)
- Double type: there are 4 values in the array (opposite to the transformation type 225)
203 - Value -> Array of Long - Creates the binary array (Array) with values of the Long type. Each value of the array has four bytes value of the vValue parameter. The vValue parameter can be of:
- Long type: there is 1 value in the array (opposite to the transformation type 223)
- Single type: there is 1 value in the array (opposite to the transformation type 224)
- Double type: there are 2 values in the array (opposite to the transformation type 225)
221 - Array -> Byte - Creates the binary value of the Byte type. The vValue parameter can be:
- Array: with 8 values of the Boolean type (opposite to the transformation type 200)
- Array: with 1 value of the Byte type (opposite to the transformation type 201)
222 - Array -> Integer - Creates the binary value of the Integer type (see Example3). The vValue parameter can be:
- Array: with 16 values of the Boolean type (opposite to the transformation type 200)
- Array: with 2 values of the Byte type (opposite to the transformation type 201)
- Array: with 1 value of the Integer type (opposite to the transformation type 202)
223 - Array -> Long - Creates the binary value of the Long type. The vValue parameter can be:
- Array: with 32 values of the Boolean type (opposite to the transformation type 200)
- Array: with 4 values of the Byte type (opposite to the transformation type 201)
- Array: with 2 values of the Integer type (opposite to the transformation type 202)
- Array: with 1 value of the Long type (opposite to the transformation type 203)
- value of the Single type (opposite to the transformation type 224)
224 - Array -> Single - Creates the binary value of the Single type. The vValue parameter can be:
- Array: with 32 values of the Boolean type (opposite to the transformation type 200)
- Array: with 4 values of the Byte type (opposite to the transformation type 201)
- Array: with 2 values of the Integer type (opposite to the transformation type 202)
- Array: with 1 value of the Long type (opposite to the transformation type 203)
- value of the Long type (opposite to the transformation type 223)
225 - Array -> Double - Creates the binary value of the Double type. The vValue parameter can be:
- Array: with 64 values of the Boolean type (opposite to the transformation type 200)
- Array: with 8 values of the Byte type (opposite to the transformation type 201)
- Array: with 4 values of the Integer type (opposite to the transformation type 202)
- Array: with 2 values of the Long type (opposite to the transformation type 203)
240 - Array -> HexaString - The input is value of the Array type with all items of the Byte type. The output is value of the String type with so-called HexaString content.
Example: If the input value of the Array type contains three values of the Byte type, for example 1A 00 B8 (in hexadecimal), then the output would be a String containing six "1A00B8" characters.
This is handy if you need to save binary data into the text.
241 - HexaString -> Array - The opposite of previous transformation, i.e. from HexaString it creates value of the Array type with all items of the Byte type
Return values:
Returns the transformed value of the respective type.
If an error occures, then the method returns: null for JavaScript or Empty pro VBScript (it can be tested by the Pm.IsValid method).
Note:
The method performs various types of the value transformations that cannot be done simply by the functions in the script.
Note for values in PLC SIMATIC S5: Values on this PLC have different internal format compared to PC format. Real values are converted by the transformation type 100 (101), Integer values are converted by the transformation type 1 (2).
Note for the BCD (Binary Coded Decimal) format: each digit of a number in the decimal notation is stored to 4 bits. It means that in the Long type there are 8 digits (range 0-99999999). This format is used often in various HW devices. The constant in the BCD format can be easily written in the way that the decimal number is introduced by the prefix for the notation in hexadecimal, so that the constant 999 transformed to BCD value is &h999.

This method is not functional in Web panels.
Example1:
Exchange of bytes in a value of the Integer type (2-bytes value)
JavaScriptVBScriptSelect and copy to clipboard

var Val = 3;
var ValNew = Pm.TransformValue(Val, 1);
In the ValNew variable is now the 768 value, which is 300 in hexadecimal. It means that the &h0003 value has been transformed to the &h0300 value.
Example2:
Converts the value 99 to BCD format (i.e. to value 153) and the checks whether an error occured.
JavaScriptVBScriptSelect and copy to clipboard

var nVal = 99;
var nBcd = Pm.TransformValue(nVal, 20);
if (Pm.IsValid(nBcd))
{
Pm.Debug("Val=" + nVal + "-> BCD=" + nBcd);   // Val=99 -> BCD=153
Pm.Debug(0x99);   // Writing the same value in the form of a constant (in hexadecimal).
}
Example3:
Converts the value -2 of the Integer type in the Val1 variable to the bit array (to the array of values of the Boolean type) into the Arr variable (the value -2 is 1111111111111110 in binary format). Then the value of the Long type is created back from this array into the Val2 variable. For control purposes the detailed information about the variables Arr and Val2 is written into the Debug item of the INFO system by the Pm.Debug method.
JavaScriptVBScriptSelect and copy to clipboard

var Val1 = CInt(-2);
var Arr = Pm.TransformValue(Val1, 200);
var Val2 = Pm.TransformValue(Arr, 222);
Pm.Debug(Arr, 1);
Pm.Debug(Val2, 1);

History:
Pm8.02.08: Generalization of transformation of the of the Double type number (transformation types 200-203, 225).
Pm8.01.05: Fixed bug: (221-224) sometimes caused excesive memory usage.
Pm8.01.02: New transformation types 240 and 241 for converting the HexaString into the byte array and back. These transformations are used for supporting the PmChar driver, but can also be used for other purposes, e.g. if you need to write binary data into the value of the String type (e.g. into a text file).
Pm8.00.02: Added new option (nType=50) for matrix transposition (exchanging the rows and columns).
PROMOTIC 9.0.18 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- LN2
- PI
- Pow
- Sin
- Tan
- TransformValue
 
 
© MICROSYS, spol. s r. o.