You are on page 1of 40

Macros for HMi

Webinar, June 07

2007 Eaton Corporation. All rights reserved.

What is a Macro in the HMi?

A Macro is a set of instructions that


extend the functionality of the HMi

Why use Macros?


A Macro allows the designer to do the following:
Let the HMi process data
Separates machine control functions from screen
management functions
Do more with less screens
Saves time (and $$)

Specific tasks that require Macros


Evaluate an expression (math)
Move data
Perform sequence of steps
Perform action based on a condition
Re-use of code
Access the Serial Port

Different Types of Macros


Global Macros

Screen Macros

Button Macros

Global Macros
Initial Macro runs once
Background Macro runs continuously
Clock Macro runs on schedule
Sub-Macro runs when called

Location of Global Macros


Select global macros from Menu->Options

Screen Macros
Screen Open Macro runs once when screen is
opened
Screen Cycle Macro runs continuously while
screen is opened
Screen Close Macro runs once when screen is
closed

Location of Screen Macros


When screen element is
active, the property
window is shown at the
right
Click on ellipses () to
open window

Button Macros
Before Execute Macro runs once prior to
button action
After Execute Macro runs once after button
action
On Macro runs once when bit is turned on
Off Macro runs once when bit is turned off

Location of Button Macros


When button element is
active, the property
window is shown at the
right
Click on ellipses () to
open window

Variables
Volatile Memory
Non-volatile memory
Indirect addressing
Recipe variables
PLC addressing
Tags in Macros
Passing variables

Volatile Memory

Each memory location is 16 bits, or 2 bytes, or 1


word
$0 through $65535 (128 Kbytes)

Non-volatile memory
Each memory location is 16 bits, or 2 bytes, or 1
word
M$0 through M$1023 (2 Kbyte)
Retentive even when loading new program into
the HMi

Indirect addressing
Use *$ to access memory indirectly
For example,
$100 = 50
$200 = 100
$300 = *$200

Q: What value is in $300?


A: 50

Recipe variables
RCPNO selected recipe #
RCPn recipe variable
See Recipe application note or user manual for
more info

PLC addressing
1@D100 base PLC address 1, word D100
2@D100 base PLC address 2, word D100
2#1@D100 link2 PLC address1 word D100
3#1@N7:1 link 3 PLC address 1, integer file
N7, word 1

Tags in Macros

Tags can be used in macros as well


Only as an assignment
$100 = VALUE

Passing values
All variables are global variables
Use direct addressing to pass a value
$100 = 50
$200 = $100

Use indirect addressing to pass an address


$100 = 50
$200 = *$100

Using Macros

Macro wizard
Update Macro
Import/Export Macros

Macro wizard
The macro wizard makes
entering code easy
Click the wizard toolbar
button in the macro
window

Macro Wizard (continued)


Click Command
Mouse over Arithmetic
Click Add

Macro Wizard (continued)


Click Variable 1
Select Internal Memory
on Link Drop Down
Select $ on Device Type
Drop Down
Addr/Value Type 1 in Text
Box
Click OK Button
Repeat for Variable 2 and
Variable 3, except enter 2
and 3 for Addr/Value

Update Macro
Updating the Macro saves
it to memory
If you do not update, the
changes will be lost!
The macro shown adds
the values in $2 and $3,
then places the result in
$1

Import/Export Macros
Allows for re-use of Macros from one button to another
Allows for re-use of Macros from one program to another

Macro Examples
Move data
Evaluate an expression
Perform a sequence of steps
Perform an action based on a condition
Re-use of code (sub-macros)
Access the serial port

Move data

$30 = 1
Assigns the value of 1 to location $30

$40 = 07DCH
Assigns the hex value 07DC to location $40

1@D100 = 5
Writes the value of 5 to D100 in the base PLC

1@D100 = $150
Assigns the value that is in memory location $150 and writes it to D100
in the base PLC

$200 = 1@D300
Reads the value in D300 and assigns it to memory location $200

1@D400 = 2#1@N7:1
Reads the value on link2 in N7:1 and writes it to D400 in the base PLC

Evaluate an expression

$101=1@D101
$102=1@D102
$100 = $101 + $102

Perform a sequence of steps


Allows the designer to add extra functions to a
button
Example:
#Set a flag, increment value, then change pages
SETB 1@M1
$100 = 1@D200
$100 = $100 + 1
1@D200 = $100
1@D0 = 101

Perform an action based on a


condition
Uses if-then-else statements
Be sure to end if-then statements with END IF
To test for two conditions, nest loops
IF $100 == 10
IF $101 == 20
1@D100 = 5
ENDIF
ENDIF

Use THEN GOTO LABEL n for jumps


IF $100 == 10 THEN GOTO LABEL 1
LABEL 1

Re-use of code (sub-macros)


Place sub-routines in sub-macros
End sub-routine with RET
Different ways of calling a sub-routine
CALL 1
CALL $100
CALL *$200

Access the serial port


Setup communications (place in Init Macro, use
Macro Wizard)
INITCOM
$1 = INITCOM(1, 2, 1, 2, 0, 6, 0)
COM2, RS485, 8, E, 1, 9600, No Flow Control

Access the serial port (continued)


Select Com port (place in Macro using the serial
port)
SELECTCOM
SELECTCOM(1)
COM2

Access the serial port (continued)


ASCII message
CHR
CHR($100,TEXT TO SEND)
$100 = TE, $101 = XT, etc.

Access the serial port (continued)


Send characters
PUTCHARS
$2=PUTCHARS($100,12,250)
Send 12 characters
Place in $100 through $105
Timeout after 250 milliseconds
$2=1 if successful

Access the serial port (continued)


Receive characters
GETCHARS
$3=GETCHARS($200,10,250)
Receive 10 characters
Place in $200 through $204
Timeout after 250 milliseconds
$3=1 if successful

Access the serial port (continued)


$1 = INITCOM(1, 2, 1, 2, 0, 6, 0)
SELECTCOM(1)
CHR($100,TEXT TO SEND)
$2= PUTCHARS($100,12,250)
$3=GETCHARS($200,10,250)

Wrap up
Macros extend the functionality of the HMi
Scripted programming language

Macros save time (and time is $$)


One screen can replace many
Maintaining one screen is easier than one-hundred

Questions???
TRC 1-800-809-2772, option 5
Tier 3 support
David Brandt
Gerry Feldmeier
Jason Hill
Jim Rosner

The End

You might also like