End Sub
Macro_Command main( ) // This main function calls the SQR()
function.
int I = 5
I = SQR(I)
SetData(I, LW_Binplc, 1,1) // Write the result to a LW
End Macro_Command
The above example code defines a sub-function called SQR(). This sub-function allows one variable to be passed
into it. The function then takes the value passed to it, multiplies its value by itself and then stores the result back
into the same variable. The result is returned back to the calling function.
Reading & Writing External Registers in a Macro
A macro program can communicate with external PLC data registers and I/O. The function GetData() receives data
from the PLC (or the OIT’s local LW and LB memory). The function SetData() sends data to the PLC (or the OIT’s
local LW and LB memory).
The GetData() or the SetData() can be hand typed according to the format listed below, or the “PlcCom” button
located at the bottom-left of the macro editor dialog box allows the user to generate the GetData() or SetData()
function code by selecting the appropriate responses within the PlcCom dialog box. Be sure to declare all variables
before using the ‘PlcCom’ option. To set up the following functions, place the cursor after the declarations, and
then press the PlcCom button. This way, all variables will be available in a drop-down menu list within the
‘PlcCom’ dialogHIDD_MACROPLCCOM.
GetData() Func tion
This function reads data from a register location in the OIT or PLC memory, and stores it into a variable.
The format for the GetData() function is:
GetData
(DestVariable, Addr_Tpe, Address, NumElements)
Parameter
Description
Example(s)
DestVariable
The name of the variable to store the
data that is captured
MyVar, InputArray[0]
Addr_Type
The device type and encoding method
(binary or BCD) of the PLC data.
LW_Binplc, 4x_Binplc,
0x_Binaux, RW_Bcdplc
Address
The address offset in the PLC (must be
written as a constant whole number – no
decimals – no variables)
0, 100, (an address that
has a decimal point is
written here without the
‘.’ So 1.03 is written as
103
NumElements
Number of elements to read/write (must
be at least 1 and it must be a constant
number) If the number of elements is
more than 1, the ‘DestVariable’
parameter must be declared as an array.
1, 16, 100
SetData() Func tion:
SetData(
DestData ,CString strAddr_Type , int iAddr_Off , int iDataCount
)
Description: Writes data from a variable to a location in the PLC memory.
Parameter
Description
Example(S)
DestData
The name of the variable to retrieve the
data from
StrAddr_Type
The device type and encoding method
(binary or BCD) of the PLC data
1010-1001a, Rev 02
256
Sil ver Se ries In stal la tion & Op er a tion Man ual
Содержание Silver HMI504T
Страница 1: ...1010 1001A Rev 02...
Страница 20: ...1010 1001a Rev 02 16 Silver Series Installation Operation Manual OIT to PC Serial Port Pin Assignments...
Страница 32: ...1010 1001a Rev 02 28 Silver Series Installation Operation Manual...
Страница 128: ...1010 1001a Rev 01 124 Silver Series Installation Operation Manual...
Страница 156: ...1010 1001a Rev 02 152 Silver Series Installation Operation Manual...
Страница 166: ...1010 1001a Rev 02 162 Silver Series Installation Operation Manual...
Страница 216: ...1010 1001a Rev 01 212 Silver Series Installation Operation Manual...
Страница 251: ...1010 1001a Rev 02 Macros 247 Set Bit Objects Attributes Dialog Project Example of Add 2...
Страница 264: ...End Macro_Command 1010 1001a Rev 02 260 Silver Series Installation Operation Manual...
Страница 268: ...1010 1001a Rev 01 264 Silver Series Installation Operation Manual...