TSL Automation Solutions Logo

Section 15.4.6 · Chapter 15: Using Macros

Data Conversion

■ BCD

Format P1 = BCD(P2) Data Type U/UD
Function Converts binary number P2 to a BCD number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The binary number to be converted.
Example 1 $U100 = BCD(0x1234) (U) /* The value of $U100 will be 1234. */

■ BIN

Format P1 = BIN(P2) Data Type U/UD
Function Converts BCD number P2 to a binary number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The BCD number to be converted.
Example 1 $U100 = BIN(1234) (U) /* The value of $U100 will be 0x1234. */

■ DW

Format P1 = DW(P2) Data Type U/S
Function Converts 16-bit number P2 to a 32-bit number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The 16-bit number to be converted.
Example 1 $U100 = DW(12345) (S) /* The value of $U100 will be 12345 and the value of $U101 will be 0. */
Example 2 $U200 = DW(-12345) (S) /* The value of $U200 will be -12345 and the value of $U201 will be 0xFFFF. */

■ W

Format P1 = W(P2) Data Type UD/SD
Function Converts 32-bit number P2 to a 16-bit number and saves the result in P1. The truncation error may occur.
P1 (I/E) The location to save the result.
P2 (I/E/C) The 32-bit number to be converted.
Example 1 $U100 = W(0x12345678) (UD) /* The value of $U100 will be 0x5678 */
Example 2 $U200 = W(-12345) (SD) /* The value of $U200 will be -12345 */

■ B2W

Format P1 = B2W(P2,P3) Data Type U
Function Converts P3-byte array starting from P2 to a P3-word array and saves the result in P1. All the high bytes of the word array are set to 0.
P1 (I) The location (or the word array) to save the result.
P2 (I) The byte array to be converted.
P3 (I/C) The size of the byte array.
Example 1 $U200 = 0x45FA
$U201 = 0xEB29
$U100 = B2W($U200, 3) /* Convert 3 bytes starting from $U200 to 3 words starting from $U100, $U100 will be 0xFA, $U101 will be?0x45 and $U102 will be 0x29. */

■ W2B

Format P1 = W2B(P2,P3) Data Type U
Function Converts a word array P2 with P3 elements to a byte array and saves the result in the byte array P1. The conversion discards the high byte of every element of the word array to form a byte array with the same number of elements. The array size cannot exceed 256.
P1 (I) The location (or the word array) to save the result.
P2 (I) The word array to be converted.
P3 (I/C) The size of the word array.
Example 1 $U200 = 0x45FA
$U201 = 0xEB29
$U202 = 0xC781
$U100 = W2B($U200, 3) /* Convert 3 words starting from $U200 to 3 bytes starting from $U100, $U100 will be 0x29FA and the low byte of $U101 will be 0x81*/

■ A2X

Format P1 = A2X(P2) Data Type U
Function Converts a 4-digit hex number in ASCII character form to a binary number and saves the result in P1. The character of the fourth digit is in the first word of the word array P2 and the characters of the other digits are in the following words in sequence.
P1 (I) The location to save the result.
P2 (I) The word array that contains the characters to be converted.
Example 1 $U20 = 49 // '1'
$U21 = 50 // '2'
$U22 = 69 // 'E'
$U23 = 70 // 'F'
$U100 = A2X($U20) /* The value of $U100 will be 0x12EF. */

■ X2A

Format P1 = X2A(P2) Data Type U
Function Converts 16-bit number P2 to a 4-digit hex number in ASCII character form and saves the result in word array P1. The character of the fourth digit is saved in the first word of P1 and the characters of the other digits are saved in the following words in sequence.
P1 (I) The location (or the word array) to save the result.
P2 (I/C) The number to be converted.
Example 1 $U10 = X2A(0x34AB) /*The 4 words starting from $U10 will be: 51('3'), 52('4'), 65('A'), 66('B') */

■ W2F

Format P1 = W2F(P2) Data Type U/S
Function Converts 16-bit number P2 to a floating point number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The 16-bit number to be converted.
Example 1 $U200 = W2F($U10) (S)

■ D2F

Format P1 = D2F(P2) Data Type UD/SD
Function Converts 32-bit number P2 to a floating point number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The 32-bit number to be converted.
Example 1 $U200 = D2F($U10) (SD)

■ F2W

Format P1 = F2W(P2) Data Type F
Function Converts floating point number P2 to a 16-bit number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The floating point number to be converted.
Example 1 $U200 = F2W($U10) (F)

■ F2D

Format P1 = F2D(P2) Data Type F
Function Converts floating point number P2 to a 32-bit number and saves the result in P1.
P1 (I/E) The location to save the result.
P2 (I/E/C) The floating point number to be converted.
Example 1 $U200 = F2D($U10) (F)

■ EXTRACT_BIT

Format P1 = EXTRACT_BIT(P2,P3) Data Type U/UD
Function Extracts bit P3 from P2 and saves the result in P1.
P1 (I) The bit to save the result.
P2 (I) The location to extract the bit.
P3 (I/C) The number of the bit to be extracted.
Example 1 $U2.0 = EXTRACT_BIT($U10, 31) (UD) /* Extract bit 31 of the double word $U10 and save the result in $U2.0 */

Need PM Designer itself?

V4 for current PK, PT, ITV and PM panels, V2 for older models. Free, sent by email.

Source.Section 15.4.6 of the PM Designer Software User Manual, Edition 2.0, © Cermate Technologies Inc. (www.cermate.com, service@cermate.com). Reproduced online, with the manual's own figures, by TSL Automation Solutions, authorised Cermate distributor, for users of Cermate HMI panels. PM Designer and PanelMaster are trademarks of Cermate Technologies Inc.

Text and figures are the manufacturer's and may describe features your panel or software version does not have. For a plain-language introduction read the PM Designer guide; for help with a specific panel contact TSL Automation.