S
MART
AXIS P
RO
/L
ITE
U
SER
'
S
M
ANUAL
FT9Y-B1378
13-19
13: S
CRIPTS
Example 1.10
Decimal to octal conversion using a while statement
Script
Operation Description
This example converts a decimal value to octal using a while statement.
By repeating the process to divide the original decimal data by 8 and converting each digit to octal in a while statement, the
conversion is implemented up to four digits.
The original decimal value is stored in D0100. After the script is executed, the converted octal value is stored in D0200.
Example 1.11
Conditional branch with switch
Script
Operation Description
If the value of D0100 is 10, then 0x1234 is stored in D0200.
If the value of D0100 is 999, then 0x5678 is stored in D0200 and D0000.01 is set to 1.
If the value of D0100 is not 10 nor 999, then nothing is executed.
// Convert a decimal value to octal
// - For example, convert 10 (dec) to 12 (oct), 16 (dec) to 20 (oct)
// - Convert a value to octal up to 4 digits max
@1 = 0;
// while counter
@2 = [D0100];
// gets original data
@3 = 1;
// decimal base
@4 = 0;
// calculation results
// repeat four times
while (@1 < 4)
{
// Extract 1st octal digit from original data. Store working result in @10.
@10 = @2 % 8;
//Convert the extracted results to decimal and add to the results
@4 = @4 + (@10 * @3);
//Increase the decimal base by one digit
@3 = @3 * 10;
// Decrease the original data by one digit
@2 = @2 / 8;
// If @2 is 0, exit the white statement
if (0 == @2)
{
break;
}
// Increment while counter by 1
@1 = @1 + 1;
}
// Store the calculation result in D0200
[D0200] = @4;
switch ([D0100])
{
case 10:
[D0200] = 0x1234;
break;
case 999:
[D0200] = 0x5678;
SET([D0000.01]);
break;
}
Содержание FT1A-B12RA
Страница 1: ...FT9Y B1378 5 ...
Страница 2: ......
Страница 208: ...7 DEVICE ADDRESSES 7 16 SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 ...
Страница 226: ...8 INSTRUCTIONS FUNCTION BLOCKS REFERENCE 8 18 SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 ...
Страница 340: ...13 SCRIPTS 13 36 SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 ...
Страница 384: ...APPENDIX A 18 SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 European Font ISO 8859 1 Cyrillic Font ANSI 1251 ...
Страница 385: ...SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 A 19 APPENDIX Japanese Font JIS X0201 ...
Страница 386: ...APPENDIX A 20 SMARTAXIS PRO LITE USER S MANUAL FT9Y B1378 ...