en-us_products:mpino_studio2:box_functions

This is an old revision of the document!


MPINO STUDIO 2 Phase 4 · Box Functions

This page explains how to enter and edit box functions, when they run, and which box functions MPINO Studio 2 provides.

Steps from creating a box function to checking its behavior

1. Create a Box Function

How to Create a Command

  1. Select a ladder cell and press \ or select Box Function from the left toolbar to place a box function cell. Then press Enter or double-click the cell to open the editor.
  2. Choose a category and command in the editor.
  3. Enter the selected argument, then press Tab for the next argument.
  4. Press Enter or OK when the command is complete.

The box function editor is where you find a command and complete its arguments. Each marker points to the item described below.

Category, command list, input field, help, and confirmation in the box function editor

  • ① Category: Choose a command group such as Timer, Counter, or Arithmetic.
  • ② Command list: Choose a command in the selected category.
  • ③ Command input: Enter the command and its arguments on one line.
  • ④ Description: Check the selected command's behavior, arguments, and example.
  • ⑤ OK and Cancel: Save the input to the cell or discard the change.

How to Read a Command

Choose a category and a command. The editor fills in the command template and selects its first argument. Enter a value and press Tab to move to the next argument. In structured commands, separate the command name and arguments with spaces.

How a command name and its arguments are entered

2. Edit an Existing Command

To edit an existing box function, select its cell and press Enter, or double-click it. Choosing another command replaces the entire input with that command's template. OK saves the change; Cancel restores the value from before editing.

Structured command boxes show each argument in its own slot, so you can select one argument to edit or copy its value.

Command name, argument slots, destination slot, and missing argument slot in a box function

Marker Item Action
① Command name Shows the command name in the band at the top of the box.
② Argument slot Shows one argument per slot. A structured command draws as many slots as it has arguments.
③ Destination slot The argument slot that stores the result is shaded and shown in bold.
④ Missing argument slot If fewer arguments are entered than the command requires, each missing position appears as a dashed slot.
Task How Result
Select an argument slot On a box function cell, press ← or →, or click a slot The selection moves one argument slot at a time. Pressing the key again at the last slot moves to the next cell outside the box.
Edit one argument Select a slot, then press Enter or double-click the slot The editor opens with only that argument selected, so typing replaces just that argument.
Paste only an argument value Press Ctrl + C on a slot that has a value, then Ctrl + V on the argument slot to paste into Only the value of that slot changes. Text copied from Notepad or another app can also be pasted; if it has several lines, only the first line is pasted.
Paste a whole box function Press Ctrl + V on a place that is not an argument slot, such as an empty cell The whole copied box function is placed from that cell to the right. If there is not enough room, a message shows how many columns are needed and nothing is pasted.
Show slot names Hold Shift in the ladder grid Each slot of a structured command box shows its slot name instead of the argument. For example, ADD shows IN0, IN1, and OUT, and TON shows OUT and PT. Missing argument slots also show their names, and releasing Shift restores the normal display.
Note on slot editing: Argument slots cannot be selected in a free-form box such as D0 = D0 + 1, or in a box drawn narrower than its argument count because of the grid edge or neighboring cells. In such a box, ← and → skip the whole box at once, and Enter opens the editor with the entire input selected.

3. Box Function Execution Condition

The ON or OFF state from the contacts on the left is the box function's input. Timers and counters process their current and done states by command even while the input is OFF. With no contact, the input is always ON. Use a positive-edge contact when a cumulative command such as INC D0 should run once.

How the left contact controls box function execution

4. Structured and Free-form Input

Structured commands are the 45 commands registered in the palette; each has a fixed syntax and argument count. Free-form input accepts an assignment containing an expression or an Arduino function call that you enter directly.

Type Example When to use
Structured MOV D0 D1 Choose a palette command and fill in its displayed arguments
Free-form D0 = readSensor() Enter a supported expression or call a function written in Arduino code

5. Call an Arduino Code Function

The two screens below show the setMotor() function written in Arduino Code and a box function that calls the same function from ladder logic.

Write the Function in Arduino Code

The setMotor() function written in Arduino Code

Call the Function from Ladder Logic

A box function that calls setMotor(100) when the M0 contact is ON

The function name, letter case, argument count, and argument types in the box function must match the definition in Arduino Code. Do not add a semicolon at the end. In this example, setMotor(100) runs while the M0 contact is ON.

View Arduino Code function-call details

6. Box Function List

Category Command Function
Timer Box Functions TON Accumulates time while the input is ON and turns the done state ON at the set value.
TOFF Turns the done state ON immediately with the input.
TPL Turns the done state ON when the input changes to ON.
TMON Starts one pulse when the input turns ON and holds the done state ON for the set time.
TMR Accumulates time while the input is ON.
TAON Provides the same on-delay behavior as TON with a default 100 ms tick.
TAOFF Provides the same off-delay behavior as TOFF with a default 100 ms tick.
TAPL Provides the same input-held pulse behavior as TPL with a default 100 ms tick.
TAMON Provides the same one-shot pulse behavior as TMON with a default 100 ms tick.
TAMR Provides the same retentive behavior as TMR with a default 100 ms tick.
Counter Box Functions CTU Increments the current value once whenever the left condition changes from OFF to ON.
CTD Preloads the current value with the set value, then decrements it once on each rising edge of the left condition.
CTUD While the left condition is ON, a rising edge on the up input adds one and a rising edge on the down input subtracts one.
Bit and Latch Box Functions SET When the left condition is ON, stores ON in an M bit or a P bit configured as an output and holds it after the condition turns OFF.
RST When the left condition is ON, stores OFF in an M bit or a P bit configured as an output.
Arithmetic Box Functions ADD Adds two values and stores the result in the destination.
SUB Subtracts the second value from the first and stores the result in the destination.
MUL Multiplies two values and stores the result in the destination.
DIV Divides the first value by the second and stores the quotient.
MOD Divides the first value by the second and stores the remainder.
INC Increments the destination by one and stores it back at the same address.
DEC Decrements the destination by one and stores it back at the same address.
SCALE Linearly maps a value from the input range to the output range and stores it in the destination. Calculates with real numbers if any argument is real, and with integers otherwise.
FLOOR Stores the greatest integer that is not larger than the source.
SQRT Stores the square root of the source.
Transfer Box Functions MOV Copies one source value to the destination.
GMOV Copies a contiguous range of D, C, or T WORD values to a destination range in the same order.
FMOV Reads one D, C, or T WORD address and fills a contiguous destination WORD range with that value.
Bitwise Operation Box Functions WAND Applies bitwise AND to two WORD values and stores the result.
WOR Applies bitwise OR to two WORD values and stores the result.
WXOR Applies bitwise XOR to two WORD values and stores the result.
WNOT Inverts every bit in the source WORD and stores the result.
SHL Shifts a WORD left and stores the result.
SHR Logically shifts a D WORD right and stores the result.
ROL Rotates a D, C, or T WORD left.
ROR Rotates a D, C, or T WORD right.
Conversion Box Functions INV Inverts every bit in the source WORD and stores the result.
NEG Reverses the sign of the source value and stores the result.
H2D Interprets a source WORD containing four BCD digits as a decimal integer and stores the result.
D2H Converts a decimal integer from 0 to 9999 into four-digit BCD and stores it in a WORD.
Logic Control Box Functions JMP When the left condition is ON, moves to a later label in the same ladder and skips the ladder rows between.
JMPN When the left condition is OFF, moves to a later label in the same ladder.
MCS Starts a master control zone at a level from 0 to 15.
MCSCLR Ends the master control zone at the specified level and any inner zones.
CLCD Box Functions CSCR When the left condition is ON, switches the LCD at I²C address ADR to screen PAGE, and keeps the last screen after the condition turns OFF. The optional third argument is the LCD response bit. Create the screens in CLCD Settings. Example: CSCR 0x27 D10 M100
Free-form Box Functions Free-form Box Functions D0 = D0 + 1 · R0 += 1.5 · D0 = readSensor()

7. Check Build Errors

An invalid command or argument appears as a build error. Check the ladder name and row in the message, then reopen that box function.

Symptom What to check
Unknown command Check the command spelling and the structured-command list
Wrong argument count Check the command syntax and spaces on its detail page
Address or type error Check the memory kind and data format in Phase 2
Possible division by zero Check the divisor or input range used by DIV, MOD, or SCALE
en-us_products/mpino_studio2/box_functions.1794497224.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki