This section describes execution conditions and programming procedure for using macro.
1-1 What is Macro?…………………………………………………………………….1 – 1
1-2 Macro Execution Condition……………………………………………………….1 – 2
1-3 Macro Programming…………………………………………………… …………1 – 8
1-1
Section 1 Outline of Macro Function
NS series Macro Reference
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 CX-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-2
Section 1 Outline of Macro Function
NS series Macro Reference
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 [PT]-[Project Properties]-[Macro] tab in CX-Designer, then set execution condition and
record macro.
For details on registering macros, refer to the online CX-Designer Help ‘System Settings and
Project Properties’.
Execution condition Explanation
When Loading a Project Execute just before loading the first screen after
starting up NS-Hardware
ON timing Alarm/Event
occurred
ON timing Alarm/Event is
canceled
When a bit changed Set macro to execute when the address of specified
When a value changed Set macro to execute when the address of specified
Execution conditions for the screen
Macro execution conditions that can be made for each screen are indicated below.
Select [PT]-[Screen/Sheet Properties]-[Macro] tab screen in CX-Designer, then set execution
condition and record macro.
For details on registering macros, refer to the online CX-Designer Help ‘Creating Screens’
Execution condition Explanation
When Loading a Screen Execute immediately after reading screen data to
When Unloading a Screen Execute immediately after closing the current screen
Execute when alarm is occurred
Execute when alarm is cancelled
bit type is changed. Up to 10 macros can be set.
word type is changed. Up to 10 macros can be set.
display the next
1-3
Section 1 Outline of Macro Function
NS series Macro Reference
Reference
Macros are executed by the timing as shown below.
NS series, NSJ series and NSH series
When loading a 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 Execute d
Screen Saver->User screen Not Executed Not Executed
NS-Runtime
When loading a 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 Execute d
Screen Saver->User screen Not Executed Not Executed
When exiting NS-Runtime - Executed
(Execute at the destination
screen)
(Execute at the destination
screen)
When unloading a screen
(Execute at the destination
screen)
When unloading a screen
(Execute at the destination
screen)
1-4
Section 1 Outline of Macro Function
NS series Macro Reference
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 the online CX-Designer Help ‘Creating 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 and comparing numeral
When Processing Display Area Execute when display area for alarm display is
When Selecting an Alarm/Event Execute just after select each alarm/event displayed
When selecting a list Execute just after select a list displayed on the List
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 when changing the value of address.
pressed.
on Alarm/Event Summary
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 Reference
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 - - OK OK OK 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 Temporary Input - - - - - Consecutive line
drawing
Document Display - - - - - Multifunction Object OK OK OK - - Contents Display - - - - - -
- - - - - -
Touch Off Timing
and comparing
Numeral
[Alarm/Event object]
Functional Object When Pressing a Display Area When selecting an Alarm/Event
Alarm/Event Display OK Alarm/Event Summary - OK
Numeral/String
When changing
Before inputting
Numeral/String
Numeral/String
Before writing
List Selection
1-6
Section 1 Outline of Macro Function
NS series Macro Reference
Reference
When a command button is set in the following functions, macros that are set at
the touch on will be executed at the touch off. Macros that are set at the off will
not be executed.
Switch screen
Control pop-up screen
Display system menu
Data block control
When functions other than above are selected, macros will be executed at the
specified timing.
Document Display is a functional object that can be used only with NS-Runtime.
1-7
Section 1 Outline of Macro Function
NS series Macro Reference
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-8
Section 1 Outline of Macro Function
NS series Macro Reference
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 $SB0 to $SB 63 (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 $SW39 (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-9
Section 1 Outline of Macro Function
NS series Macro Reference
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 3000characters.
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-10
Section 1 Outline of Macro Function
NS series Macro Reference
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-11
Section 1 Outline of Macro Function
NS series Macro Reference
Basic Operational Statements
The following operational statements can be used in the program.
Item Operator 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 ltic shifted B-
Bit Shift (right) >> C = A>>B Se the value that A is arithmetic
bit to the left to C.
shifted B-bit to 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-12
Section 1 Outline of Macro Function
NS series Macro Reference
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 character
strings
Alarm/Event summary Clear the number of Alarm/Event
HMI exclusive statements
Communications
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
Write data to specified address WRITECMEM
Read bit data from specified
address
Read word data from specified
address
Write bit data to specified address WRITEHOSTB
STRM2W
STRW2M
RSTALARMCNT
GETNUMVAL
GETPARTS
READHOSTB
READHOSTW
Write word data to specified
address
Process termination Terminate macro program RETURN
Set Date/Time Change settings of internal clock of
the PT
Reading/writing data
Write to multiple addresses
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).
Write (0/1) to multiple bit addresses
in the PT memory
Write a value to multiple word
addresses in the PT memory
WRITEHOSTW
SETTIME
READCF
WRITECF
BITSET
MEMSET
1-13
Section 1 Outline of Macro Function
NS series Macro Reference
Data manipulation
/conversion
Repeat Program
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
Aborting from Program Repetition BREAK
Return to the top of FOR loop. CONTINUE
SWAP
SWAPL
MEMCOPY
SETFOCUS Input Focus Control
RELEASEFOCUS
1-14
Section 1 Outline of Macro Function
A
A
NS series Macro Reference
The timing when a function can be executed as shown below.
OK OK OKOKOK OKOKOK OK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOKOKOK OK OKOK OK
* *
OKOK OKOKOKOK OK OKOK OK
OKOK OKOKOKOK OK OKOK OK
OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OKOKOKOKOKOK OK OKOK OK
OKOKOKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OKOK OKOKOK OKOK OK
OKOK OKOKOK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
OK OKOKOKOK OKOKOKOK OK OKOK OK
*Numeral Display & Input Only
1-15
Section 1 Outline of Macro Function
NS series Macro Reference
Added Functions
Action Function Remarks
Set Date/Time SETTIME Added in the NS system program
Data manipulation
/conversion
Switch Screen (BCD) SHOWPAGEBCD
Repeat Program
Communications
addresses
READCF Reading/writing data
WRITECF
SWAP
SWAPL
MEMCOPY
SETFOCUS Input Focus Control
RELEASEFOCUS
FOR, NEXT
BREAK
CONTINUE
READHOSTB
READHOSTW
WRITEHOSTB
WRITEHOSTW
BITSET Write to multiple
MEMSET
Ver.3.0
Added in the NS system program
Ver.4.0
Added in the NS system program
Ver.5.0.
Added in the NS system program
Ver.6.0
Added in the NS system program
Ver.6.2
1-16
Section 1 Outline of Macro Function
NS series Macro Reference
In addition to macro of NS Series, the following functions are provided for macro of NS-Runtime.
Action Function
Manipulating
character strings
Manipulating
Window
Module startup
String Comparison (Case sensitive) STRCMP/STRCMPW
String Comparison (Not case sensitive) STRICMP/STRICMPW
String Concatenation STRCAT/STRCATW
Gets String Length STRLEN/STRLENW
Extracts the specified number of
characters from the leftmost characters of
a string.
Extracts the specified number of
characters from a specified character
position of a string.
Extracts the specified number of
characters from the rightmost characters
of a string.
Deletes the leftmost spaces of a string STRLTRIM/STRLTRIMW
Deletes the spaces at both sides of a
string
Deletes the rightmost spaces of a string STRRTRIM/STRRTRIMW
Converts a string to lower case STRLWR/STRLWRW
Converts a string to upper case STRUPR/STRUPRW
Finds a window title WINFIND
Maximizes a specified window WINMAX
Minimizes a specified window WINMIN
Restores a size of a specified window WINNORMAL
Brings a specified window to the front WINTOP
Exits a specified window WINTERM
Starts up an application EXEC
STRLEFT/STRLEFTW
STRMID/STRMIDW
STRRIGHT/STRRIGHTW
STRTRIM/STRTRIMW
Reference
These macros cannot be used with NS series, NSJ series and NSH series.
1-17
Section 1 Outline of Macro Function
NS series Macro Reference
The timing when a function can be executed as shown below.
Project Macro
When Loading a Project
Alarm/Event On Timing
STRCMP(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRICMP(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRCAT(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRLEN(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRLEFT(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRMID(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRRIGHT(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRLTRIM(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRTRIM(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRRTRIM(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRLWR(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
STRUPR(W) OK OK OK OK OK OK OK OK OK OK OK OK OK
WINFIND OK OK OK OK OK OK OK OK OK OK OK OK OK
WINMAX OK OK OK OK OK OK OK OK OK OK OK OK OK
WINMIN OK OK OK OK OK OK OK OK OK OK OK OK OK
WINNORMAL OK OK OK OK OK OK OK OK OK OK OK OK OK
WINTOP OK OK OK OK OK OK OK OK OK OK OK OK OK
WINTERM OK OK OK OK OK OK OK OK OK OK OK OK OK
EXEC OK OK OK OK OK OK OK OK OK OK OK OK OK
Screen
Macro
Alarm/Event Off Timing
When Loading a screen
When Unloading a screen
Functional object Macro
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-18
Section2 Functions
NS series Macro Reference
Section2 Functions
This section describes how to use the standard functions.
2-1 Table of Function and Argument....................................................................................... 2
2-2 Details of the Function....................................................................................................... 7
1
Section2 Functions
NS series Macro Reference
2-1 Table of Function and Argument
The varity of variables and values, which can be specified as an argument for macro function is
described below. Alphabets such as S,D,n,x,y in the row indicated parameter used in “2-2”
Details of function”-“Format”.
Argument
Function
BCD S ○ ○ ○ ○ ○
BIN
CLOSEPOPW n ○ ○ ○ ○ ○
GETNUMVAL
GETPARTS
MOVEPARTS
MOVEPOPW
MOVEPOPWDOWN
MOVEPOPWLEFT
MOVEPOPWRIGHT
MOVEPOPWUP
MSGBOX
S
None
N
Left, Top,
Right,
Bottom
n ○ ○ ○ ○ ○
X
Y ○
n
x ○ ○ ○ ○ ○
y
n
y ○
n
x
n
y
n ○ ○ ○ ○ ○
y ○
S1
S2 ○ ○ ○ ○
S3
$B $HB $SB
○ ○ ○ ○ ○
○
○ ○ ○
○
○
○○
○○
○○
○○○
PT Memory
Numerical
access of bit
$W $HW $SW
Long access of
word
Constant
String
○○○○
○○○○ ○○○○ ○○○○
○○○○ ○○○○ ○○○○
○○○○ ○○○○
○○○○ ○○○○
○○○○
○○○○○ ○
Host Side Address
Specify Index
2
Loading...
+ 51 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.