macros for hmi
DESCRIPTION
HMITRANSCRIPT
![Page 1: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/1.jpg)
© 2007 Eaton Corporation. All rights reserved.
Macros for HMi
Webinar, June 07
![Page 2: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/2.jpg)
What is a Macro in the HMi?
• A Macro is a set of instructions that extend the functionality of the HMi
![Page 3: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/3.jpg)
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 $$)
![Page 4: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/4.jpg)
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
![Page 5: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/5.jpg)
Different Types of Macros
• Global Macros
• Screen Macros
• Button Macros
![Page 6: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/6.jpg)
Global Macros
• Initial Macro – runs once
• Background Macro – runs continuously
• Clock Macro – runs on schedule
• Sub-Macro – runs when called
![Page 7: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/7.jpg)
Location of Global Macros
• Select global macros from Menu->Options
![Page 8: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/8.jpg)
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
![Page 9: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/9.jpg)
Location of Screen Macros
• When screen element is active, the property window is shown at the right
• Click on ellipses (…) to open window
![Page 10: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/10.jpg)
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
![Page 11: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/11.jpg)
Location of Button Macros
• When button element is active, the property window is shown at the right
• Click on ellipses (…) to open window
![Page 12: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/12.jpg)
Variables
• Volatile Memory• Non-volatile memory• Indirect addressing• Recipe variables• PLC addressing• Tags in Macros• Passing variables
![Page 13: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/13.jpg)
Volatile Memory
• Each memory location is 16 bits, or 2 bytes, or 1 word
• $0 through $65535 (128 Kbytes)
![Page 14: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/14.jpg)
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
![Page 15: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/15.jpg)
Indirect addressing
• Use *$ to access memory indirectly
• For example, • $100 = 50• $200 = 100• $300 = *$200
• Q: What value is in $300?
• A: 50
![Page 16: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/16.jpg)
Recipe variables
• RCPNO – selected recipe #
• RCPn – recipe variable
• See Recipe application note or user manual for more info
![Page 17: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/17.jpg)
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
![Page 18: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/18.jpg)
Tags in Macros
• Tags can be used in macros as well
• Only as an assignment• $100 = VALUE
![Page 19: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/19.jpg)
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
![Page 20: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/20.jpg)
Using Macros
• Macro wizard
• Update Macro
• Import/Export Macros
![Page 21: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/21.jpg)
Macro wizard
• The macro wizard makes entering code easy
• Click the wizard toolbar button in the macro window
![Page 22: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/22.jpg)
Macro Wizard (continued)
• Click Command• Mouse over Arithmetic• Click Add
![Page 23: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/23.jpg)
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
![Page 24: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/24.jpg)
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
![Page 25: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/25.jpg)
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
![Page 26: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/26.jpg)
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
![Page 27: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/27.jpg)
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
![Page 28: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/28.jpg)
Evaluate an expression
• $101=1@D101
• $102=1@D102
• $100 = $101 + $102
![Page 29: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/29.jpg)
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
![Page 30: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/30.jpg)
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
![Page 31: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/31.jpg)
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
![Page 32: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/32.jpg)
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
![Page 33: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/33.jpg)
Access the serial port (continued)
• Select Com port (place in Macro using the serial port)
• SELECTCOM• SELECTCOM(1)• COM2
![Page 34: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/34.jpg)
Access the serial port (continued)
• ASCII message
• CHR• CHR($100,”TEXT TO SEND”)• $100 = “TE”, $101 = “XT”, etc.
![Page 35: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/35.jpg)
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
![Page 36: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/36.jpg)
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
![Page 37: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/37.jpg)
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)
![Page 38: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/38.jpg)
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
![Page 39: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/39.jpg)
Questions???
• TRC 1-800-809-2772, option 5• Tier 3 support
• David Brandt• Gerry Feldmeier• Jason Hill• Jim Rosner
![Page 40: Macros for HMi](https://reader034.vdocuments.site/reader034/viewer/2022042706/577cb44e1a28aba7118c66c5/html5/thumbnails/40.jpg)
The End