Omron NS8 Reference Manual

MACRO REFERENCE
NS-Series
Cat. No. V075-E1-04
Section 1 Outline of Macro Function
NS series Macro Referenc
1-1

Section 1 Outline of Macro Function

NS series Macro Referenc
Section 1 Outline of Macro Function
This section describes execution conditions and programming procedure for using macro.
1-1 What is Macro?…………………………………………………………………….1 – 2 1-2 Macro Execution Condition……………………………………………………….1 – 4 1-3 Macro Programming…………………………………………………… …………1 – 7
1-2
Section 1 Outline of Macro Function
NS series Macro Referenc

1-1 What is Macro?

Macro is the function which can be executed by users original program. User can add functions, such as arithmetic operations and distinction of conditions, which are not supported by standard functions in NS-Designer. This function allows the PT to process screen display or data, which is performed by PLC before. It is also possible to reduce a load of PLC. In this manual, the timing for executing macro is called “Macro Execution Condition”. Macro can be made by roughly divided three execution conditions as shown below.
-Execution condition for the project
-Execution condition for the screen
-Execution condition for the functional objects There is no restriction on the number of macros for 1 project/1screen.
Up to 3000 characters can be used for one macro. Line feed is counted as two characters. There is also no restriction on the number of lines.
Example: ‘Number of inputting characters 11 characters+line
b feed (2characters), including comment $W0=10; 7characters+line feed (2characters) STRCPY($W10”,ABCDE”); 21characters In this case, 43 characters are used.
1-3
Section 1 Outline of Macro Function
NS series Macro Referenc

1-2 Macro Execution Condition

Macros can be created for each project, screen, and functional objects. Also they can be created for the following execution conditions.
Executing conditions for the project
Macro execution conditions that can be made for the project are indicated below. Select [Settings]-[Project properties]-[Macro] tab in NS-Designer, then set execution condition and record macro. For details on registering macros, refer to NS-Designer operation manual “6-1 Registering Macros”-“6-1-1Registering Macros to Projects”.
Execution condition Explanation When Loading a Project Execute just before loading the first screen after
starting up NS-Hardware Alarm/Event ON Timing Execute when alarm is occurred Alarm/Event OFF Timing Execute when alarm is cancelled
Execution conditions for the screen
Macro execution conditions that can be made for each screen are indicated below. Select [Settings]-[Screen properties]-[Macro] tab screen in NS-Designer, then set execution condition and record macro. For details on registering macros, refer to NS-Designer operation manual “6-1 Registering Macros”­“Registering Macros to Screens”.
Execution condition Explanation
When Loading a Screen Execute immediately after reading screen data to
display the next When Unloading a Screen Execute immediately after closing the current screen
Reference
Macros are executed by the timing as shown below.
When loading a screen
(Execute at the destination
screen) User screen->User screen Executed Executed User screen->Transfer screen Not Executed Executed User screen->System menu Not Executed Executed System menu->User screen Executed Not Executed User screen->Screen Saver Not Executed Not Executed Screen Saver->User screen Not Executed Not Executed
1-4
When unloading a screen (Execute at the destination screen)
Section 1 Outline of Macro Function
NS series Macro Referenc
Execution conditions for the functional objects
Macro execution conditions that can be made for each functional object are described in the following table. Open property dialog for each functional object and select [Macro] tab page, then set the execution condition and create macro. For details on registering macros, refer to NS-Designer operation manual “6-1 Macro Registration”-“Registration for the functional objects”.
Execution condition Explanation Touch on Timing Execute when functional object is pressed. Touch off Timing Execute when functional object is released Before Inputting numeral or character string Before Writing numeral or character string When changing numeral and character string When Processing Display Area Execute when display area for alarm display is
When Selecting an Alarm/Event Execute just after select each alarm/event When selecting a list Execute just after select a list displayed on the
Execute just before display tenkey pad or virtual keyboard for inputting values or strings Execute just before notice numeral and character string to the host. Execute then changing the value of address.
pressed. displayed on Alarm/Event Summary List Selection.
Note
If the password is set for functional objects, the following macros are executed after inputting the password. If the password has been cancelled for inputting, macros will not be executed.
- Touch on/Touch off timing
- Before inputting Numeral/Character string
- When pressing Display Area
- When selecting an Alarm/Event
- When selecting a list
1-5
Section 1 Outline of Macro Function
NS series Macro Referenc
The following conditions can be selected for functional objects.
Touch on Timing
Functional Object
ON/OFF Button OK OK - - - ­Word Button OK OK - - - ­Command Button OK OK - - - ­Bit Lamp - - OK - - ­Word Lamp - - OK - - ­Numeral Display & Input String Display & Input - - OK OK OK ­Thumbwheel Switch - - OK - OK ­Text - - - - - ­List Selection - - - - - OK Level Meter - - - - - ­Broken-line Graph - - - - - ­Bitmap - - - - - ­Analogue Meter - - - - - ­Video Display - - - - - ­Date - - - - - ­Time - - - - - ­Data Log Graph - - - - - ­Data Block Table - - - OK OK -
[Alarm/Event object]
Functional Object When Pressing a Display Area When selecting an Alarm/Event Alarm/Event Display OK ­Alarm/Event Summary - OK
- - OK OK OK -
Touch Off Timing
Numeral/String
When changing
Numeral/String
Before inputting
Numeral/String
Before writing
List Selection
1-6
Section 1 Outline of Macro Function
NS series Macro Referenc

1-3 Macro Programming

This section describes macro creation procedures and programming terms.
The Method for Writing a Macro
Delimiter of the Program
Put a semicolon (;) at the end of each program as a delimiter. However, it is not necessary for IF (), ELSEIF (), ELSE(),ENDIF.
Example; $W0=2; IF ($W0>=10) $W5=$W0-$W2; ELSE $W5=$W0+$W2; ENDIF
Comment
Put single quotation mark at the beginning of the sentence when you add the comment for each program. From single quotation mark (‘) to the end of character sting will be regarded as a comment. Example: $W0 = 100; ‘Comment ‘Comment IF ($W1==200)
···
Writing Programming Terms
Both uppercase and lowercase can be used for programming macros because they are not classified. Example:
-MovePopwDown () and MOVEPOPWDOWN() are regarded as same function.
-[Host1:DM0]and [host1:dm0] are regarded as same host address.
1-7
Section 1 Outline of Macro Function
NS series Macro Referenc
Programming Terms
This section describes terms used in this function.
Variable
The following variables can be used in macro program.
Item Explanation Host address
PT Memory Bit
Index Index is used for processing bit and word in the PT memory.
Use functions (READCMEM and WRITECMEM) for communication when accessing to the address in the host. Enclose address in [ ] Example: READCMEM($W100,[HOST1:DM00000],100); ‘Read HOST1:DM00000 to DM00099 to $W100 to $W199
Internal memory: $B $B0 to $B32767 (1bit per 1point) Internal Holding memory: $HB $HB0 to $HB8191 (1bit per 1point) System Memory: $SB $SB 47 (1bit per 1point) Word Internal memory: $W $W to $W32767(16bit per 1point) Internal Holding memory: $HW $HW0 to $HW 8191 (16bit per 1point) System Memory: $SW $SW0 to $SW36 (16bit per 1point) Example: $W100=$W0+1; ‘Set the value $W0 and 1 added to $W100
Add index to the end of the address and it will processed as [specified address + index value] There are 10 index points (I0 to I9). Set I0 to I9 for the value of $SW27 to $SW36. Example: $SW27 = H20; $W0I0 = 123; ‘$W0I0 is regarded as $W20 added $W0 and 20 ‘$W20 = 123
Qualifier of Variable
Qualifiers set for variables must be used as shown below. Qualifiers are used when performing 32-bit data processing and numeral processing for bit.
Item Explanation Long Access (32bit) of Word (16bit)
Numeral Access of Bit
Put “L” at the end of variable. Uses 2 words. $W0L=1000000; ‘Accesses regarding $W0, $W1 as 32-bit
$W100L=1000*1000; ‘Accesses regarding $W100, $W101 as 32-bit Put “:n” at the end of variable. Specify the value of bit address (up to 32 by 4-bit unit) for “n”. Exceptions: If n=16, input ”W”. If n=32, input “L”. $B0:4 = 3; ‘Sets 3(0011) for 4-bit from $B0 to $B3 $B0W = 12345; ‘Sets 12345(0011000000111001) for 16-bit from $B0 to ‘$B15
1-8
Section 1 Outline of Macro Function
NS series Macro Referenc
Constant
Usable constants for macro program and procedure are described in the following table.
Item Explanation
Decimal constant -32768 to 32767 can be input when using word (16-bit)
-2147483648 to 2147483647 can be input when using 2 words (32-bit)
Hexadecimal constant H0 to HFFFF can be input when using word (16-bit)
H0 to HFFFFFFFF can be input when using 2 words (32-bit)
Character String Enclose in “ “
E.g. ”ABCDE”
Branches
The following keywords can be used for specifying conditions.
Item Explanation IF ELSEIF ELSE ENDIF
Enclose conditional expressions in parentheses () after the IF and ELSEIF. Always use ENDIF at the end. Up to 8 nests can be input. There is no restrictions for inputting the number of lines under IF sentence. However, the total number of characters used in whole macro must be no more than 1024 characters. E.g. IF($W100 == 1) ‘If $W100 is 1 $W99 = 1; ELSEIF($W100 == 2) ‘if $W100 is 2 $W99 = 2; ELSE ‘if $W100 is other than 1 or 2 $W99 = 3; ENDIF
1-9
Section 1 Outline of Macro Function
NS series Macro Referenc
Conditional Expressions
Use the following conditional expressions for specifying conditions in the IF sentences. It works for all types of data (word, long access of word, bit, and numeral access of bit).
Item Explanation A == B If A is equal to B, TRUE. A > B If A is greater than B, TRUE. A >= B If A is greater than or equal to B, TRUE. A < B If A is less than B, TRUE. A <= B If A is less than or equal to B, TRUE. A <> B A ! = B A && B A AND B A || B A OR B
If A is not equal to B, TRUE. If both A and B are true, TRUE. (AND) If either of A or B is true, TRUE. (OR)
Reference
The result (A&&B, A>B) can be substituted for the variable. E.g.$B100=$W0>100; If the value of $W is “100” or less, “0” will be substituted for $B100. If the value of $W is more than ”100”, “1” will be substituted for $B100.
1-10
Section 1 Outline of Macro Function
NS series Macro Referenc
Basic Operational Statements
The following operational statements can be used in the program.
Item symbol Example meaning substitution = A = B Substitute B for A addition + C = A+B Set A+B to C subtraction - C = A–B Set A–B to C multiplication * C = A*B Set AxB to C division / C = A/B Set A/B to C residue % C = A%B Set A%B to C OR | C = A|B Logically ORs for A and B AND & C = A & B Logically ANDs for A and B NOT ! C = !A Set C for denial of A Exclusive ˆ C = A^B Result C of logical XORs for A and B Complement of 1 ~ B = ~A Set the 1-complement of A to B Bit Shift (left) << C = A<<B Set the value that A is shifted B-bit to
Bit Shift (right) >> C = A>>B Se the value that A is shifted B-bit to
the left to C. the right to C.
Reference
If executing logical operation, process must be performed between the same data types (between word, bit, or long access) E.g.$SW0L=$SW10L&$W20L;’Use all long access of word’
Multiple operations can be combined. E.g. A=(B+C)*(D+E/2)
The priority of orders is as follows.
Item Symbol High ( ) ~ *, /,% +, ­ << ,>> & ˆ | Low =
1-11
Section 1 Outline of Macro Function
NS series Macro Referenc
Functions
The following functions are provided for macro of NS Series.
Action Function
Value (BIN code)->BCD code BCD Conversion between BCD
and BIN Manipulating characte r
strings
Alarm/Event summary Clear the number of Alarm/Event
HMI exclusive statements
Process termination Terminate macro program RETURN Set Date/Time Change settings of internal clock of
Data manipulation /conversion
Repeat Program
BCD code->value (BIN code) BIN Copy character string STRCPY/STRCPYW
Convert from ASCII code to Unicode
Convert from Unicode to ASCII code
occurrence Output written value and changed
value Switch screen SHOWPAGE/SHOWPAGEBCD
Movement of object display area MOVEPARTS Display message dialog box MSGBOX
Get displayed rectangle of the object Move pop-up window MOVEPOPW
Move pop-up window up MOVEPOPWUP Move pop-up window down MOVEPOPWDOWN
Move pop-up window left MOVEPOPWLEFT Move pop-up window right MOVEPOPWRIGHT
Close pop-up window CLOSEPOPW Read data from specified address READCMEM Communications Write data to specified address WRITECMEM
the PT Read contents (values in binary) of
the specified file in a memory card (CF) to PT memory. Save the contents of PT memory in a memory card (CF). Swap high order and low order of the specified address.
Swap high order (2byte) and low order (2byte) of the specified long word data.
Copy contents of $W in the PT memory Set the input focus for the specified object Release the input focus set for the object Repeat Program FOR, NEXT
STRM2W
STRW2M
RSTALARMCNT
GETNUMVAL
GETPARTS
SETTIME
READCF Reading/writing data
WRITECF SWAP
SWAPL
MEMCOPY SETFOCUS Input Focus Control RELEASEFOCUS
Aborting from Program Repetition BREAK Return to the top of FOR loop. CONTINUE
1-12
Section 1 Outline of Macro Function
NS series Macro Referenc
The timing when a function can be executed as shown below.
BCD OK OK OK OK OK OK OK OK OK OK OK OK OK BIN OK OK OK OK OK OK OK OK OK OK OK OK OK CLOSEPOPW OK OK OK OK OK OK OK OK OK OK OK OK GETNUMVAL
GETPARTS OK OK OK OK OK OK OK OK OK OK MOVEPARTS OK OK OK OK OK OK OK OK OK OK
MOVEPOPW OK OK OK OK OK OK OK OK OK OK OK OK MOVEPOPWDOWN OK OK OK OK OK OK OK OK OK OK OK OK
MOVEPOPWLEFT OK OK OK OK OK OK OK OK OK OK OK OK MOVEPOPWRIGHT OK OK OK OK OK OK OK OK OK OK OK OK
MOVEPOPWUP OK OK OK OK OK OK OK OK OK OK OK OK MSGBOX OK OK OK OK OK OK OK OK OK OK OK OK OK
READCMEM OK OK OK OK OK OK OK OK OK OK OK RETURN OK OK OK OK OK OK OK OK OK OK OK OK OK RSTALARMCNT OK OK OK OK OK OK OK OK OK OK OK OK OK
SHOWPAGE OK OK OK OK OK OK OK OK OK OK OK OK OK SHOWPAGEBCD OK OK OK OK OK OK OK OK OK OK OK OK OK STRCPY(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRM2W OK OK OK OK OK OK OK OK OK OK OK OK OK WRITECMEM OK OK OK OK OK OK OK OK OK OK OK
SETTIME OK OK OK OK OK OK OK OK OK OK OK OK OK READCF OK OK OK OK OK OK OK OK OK OK OK OK OK
WRITECF OK OK OK OK OK OK OK OK OK OK OK OK OK MEMCOPY OK OK OK OK OK OK OK OK OK OK OK OK OK
SWAP OK OK OK OK OK OK OK OK OK OK OK OK OK SWAPL OK
SETFOCUS OK OK OK OK OK OK OK OK RELEASEFOCUS OK OK OK OK OK OK OK OK
Project Macro Screen
When Loading a Project
Alarm/Event On Timing
Alarm/Event Off Timing
Macro
When Loading a screen
*
Numeral Display & Input Only
Functional object Macro
When Unloading a screen
Touch On Timing
Touch Off Timing
When changing value
*
Before Inputting Numeral/String
When writing Numeral/String
List Selection
When pressing a Display Area
When Selecting an Alarm/Event
*
1-13
Loading...
+ 31 hidden pages