Script
Script
This chapter explains the basics of creating and using programming scripts in GP-Pro EX.
Please start by reading “20.1 Settings Menu” (page 20-2) and then turn to the corresponding
page.
20-1
Settings Menu
You can use D-Scripts to create simple programs. Using this feature, you can perform
operations in the GP or communicate between the GP and unsupported peripheral devices.
Be sure to not use D-Scripts/Global D-Scripts to control systems that can cause life-
threatening or serious injury.
• D-Scripts are set up on a Base Screen. That Base Screen looks at the
conditions while it is displayed and executes the script.
• When the GP is running, a Global D-Script runs based on the trigger,
regardless of the screen displayed.
• Extended Scripts should be used for high-level communication programs.
• In addition to scripts, you can use logic programs for control applications.
) “28.1 Setup Menu” (page 28-2)
Conditional Operations
Create a script which changes screens to screen number 7 ) Setup Procedure (page 20-6)
after three seconds. ) Introduction (page 20-5)
After After After
1 second 2 seconds 3 seconds
Time
Process Script Process Process Process
D0099 C D0200 C
B B
D0000 A D0101 A
Screen 1 Screen 2
D20
0 ≤3
0 Screen 3
Temperature is
too low.
GP
Start ON
Action
Create a script which automatically changes screens to screen number 7 after 3 seconds.
After After After
1 second 2 seconds 3 seconds
Time
Process Script Process Process Process
Commands Used
Command Function Summary
Assignment (=) Assigns the right side value to the left side.
Addition (+) Adds a constant to a Word device's data.
if ( ) When a condition becomes true, the process following the "if ( )"
statement is executed.
Equivalent (==) Compares the value on the right and left sides. Becomes true if the
left side equals the right side.
LS0008 Changes to the screen number stored in this value.
) “A.1.4.2 System Data Area” (page A-11)
Triggered Condition
Select the timer as below and set the [Timer Settings] to 1 second.
Completed Script
Creation Procedure
1 From the [Common Settings (R)] menu, select [Global D-Script Settings (L)].
2 Click [Create]. To view an existing script, select the ID number and click [Edit], or double-
click the ID number row.
4 Select [Timer] in the Script Trigger Conditions (trigger), select [Timer] and specify the
[Timer Settings] as 1 second.
5 Click the [Tool Box] tab. The toolbox allows you to easily place a command to use in the
script.
6 Create the first line of script. If you specify the D00100 default value as 0, the first line
operation is a count operation that increases and stores the count every time a process
completes.
Click and select [Word Address], click .
10 Click [Addition (+)] and type "1". The first row is now complete.
11 Create the second row of the script. In the second row, when a condition becomes true, the
process following the "if ( )" statement is executed. Click [if - endif].
12 Create the condition expression inside the brackets "( )" following "if". The condition
expression compares the value stored in D00100 to "3", and turns true if they are equal. Place
the cursor inside the brackets "( )" and repeat steps 6 to 7 to place another D00100.
13 Click [Equivalent (==)] and input "3". The second row is now complete.
14 Place the cursor inside the "{ }" brackets and press Enter. Repeat steps 6 to 7 to place another
LS0008.
• When selecting text, press the [Ctrl] Key + [Shift] Key + [->] Key or [<-]
Key to select the entire text block.
• Press the [Ctrl] Key + [F4] Key to close the currently selected display.
• Press the [Esc] Key to overwrite the script or to delete and exit.
Action
Create a script which detects the rising edge (0 to 1) of bit address M0100 and copies data
stored in the connected device into another address.
D0099 C D0200 C
B B
D0000 A D0101 A
Commands Used
Command Function Summary
Copy Copies a stored value into a device in one operation.
Memory Data for the number of Addresses will be copied to the copy destination
memcpy ( ) Word Addresses beginning from the source data's first Word Address.
[Format]
memcpy ([Copy To Address], [Copy From Address], Words)
Triggered Condition
In [Trigger Condition], select [Bit ON], and set the [Bit Address] to M000100.
Completed Script
Creation Procedure
1 From the [Parts (P)] menu, select [D-Script (R)] or click from the toolbar.
2 Click [Create]. The IDs for existing scripts are displayed in the [D-Script List].
4 Select [Bit ON] in the Script Trigger Conditions (trigger) and specify M000100 as [Bit
Address].
5 Click the [Function] tab. The built-in functions allow you to easily place a command to use in
the script.
Action
The temperature management system detects an error bit from the connected device and
displays alarm messages when the temperature information storage address (D200) rises to
70 degrees C or higher, or falls to 30 degrees C or lower. Also, this script counts the number
of detected errors.
Screen 1 Screen 2
D200≥70
Tank temperature Temperature is
D200 50 too high!!
D20
0≤ 3
0
Screen 3
Temperature is
too low.
The address that counts each time D200 rises to 70 degrees C or higher and stores the
number of times:LS0300
The address that counts each time D200 falls to 30 degrees C or lower and stores the
number of times:LS0301
The address that stores the screen number to display an alarm screen:LS0302
Commands Used
Triggered Condition
In [Trigger Condition], select [Bit ON], and set the [Bit Address] to M000100.
Completed Script
Creation Procedure
1 From the [Parts] menu click [D-Script (R)] or click .
2 Click [Create]. The IDs for existing scripts are displayed in the [D-Script List].
5 In [Trigger Conditions], select [Bit ON], and specify the [Bit Address] as M00100.
6 Create a program in the Action area by entering Functions, Statements, and Expressions. The
setting is complete.
• When selecting text, press the [Ctrl] Key + [Shift] Key + [->] Key or [<-]
Key to select the entire text block.
• Press the [Ctrl] Key + [F4] Key to close the currently selected display.
• Press the [Esc] Key to overwrite the script or to delete and exit.
Action
This example creates an extended script to output the data read from a barcode connected to
the USB to a serial printer connected to COM1.
GP
Start ON
GP
Buffer
Receive databuf0
Buffer
databuf1
Device/PLC Extended Script
Send databuf2
Buffer databuf3
Internal Memory
databuf0-databuf3
These are byte (8-bit) memory spaces used for data storage. The buffer size is 1 KB.
Main function
Decides whether or not to start the printing when the Printer
Start Button turns ON.
Flow Chart
Clear Error
Yes
Extended SIO
Initialization
Finish
Printer Initialization
Execution of Data
Transmission
Finish
Send
Finish
Function Summary
When the Printer Start Button (internal memory 005000) turns ON, decides whether or not to
start printing from the 1st byte of Print Permit data.
The Print Permit data performs the following actions as an example of the printer
specifications.
Print Preparation OK: Send 0x31 (ASCII code "1") to the device/PLC.
Print Preparation Invalid: Send 0x30 (ASCII code "0") to the device/PLC.
The GP receives the Print Permit data in databuf0 and this data is moved to accessible
internal memory 100 with the following script handling.
When internal memory 100 = 0x31 (ASCII code for the value "1"), printing starts. When
internal memory is 0x30 (ASCII code for "0") it returns to the beginning and repeats this
process until the 0x31 data is received.
Created Screen
Function Summary
Configure the Send Buffer, Receive Buffer, and Error initialization.
Function Summary
Initializes the printer. Send the ESC/P command "ESC+@" to the printer.
GP
1 2
databuf0 databuf1
0x1B 0x40
( “ESC” ) ( “@” )
3
databuf0
“ESC+@”
( “ESC+@” )
Function Summary
1 Append the text “Price:” and “Yen” to the price data stored internal memory 0500.
From screen
Price
(0500)
GP
XXX Yen
1
databuf0 databuf1 2
Changes text and stores
Price: it in databuf1.
3
databuf0
Price: GP
3 4
databuf0 databuf1
Price: Yen
5
databuf0
Price: Yen
2 Change the data format in order to send print data to the printer. Divide the string data
(Product Name) stored sequentially in internal memory 1000 into byte units, and store into
internal memory 2000 to 2030 as low order byte string data. Use the function _ldcopy and
store the data in databuf2 in order of the consecutive word address's lowest byte.
• The _ldcopy function takes data stored as Words, and stores only the lower
order bytes in the buffer, while higher order byte data is ignored.
From screen
Product Name
(1000)
Pro-face
GP
1 2
databuf1 databuf2
3
databuf1
3 4
databuf1 databuf0
5
databuf1
Function Summary
1 Append a "line feed" to allow for continuous printer output.
GP
1 2
databuf1 databuf0
Product Name: Pro-face Price: XXX Yen 0x0d
("CR")
3
databuf1
3 4
databuf1 databuf0
Product Name: Pro-face Price: XXX Yen "CR" 0x0a
("LF")
5
databuf1
Commands Used
Creation Procedure
1 Set the Extended Script used to communicate. From the [Project (F)] menu, point to [System
Settings (C)] and select [Script Settings]. Set the [Type] to [Extended Script].
3 Register "INIT" as a User-Defined Function. Click the [Function] tab and click the user-
defined function frame's [Create] button.
4 Input [INIT] as the function name, click [OK]. The following screen appears.
5 Create a script in the Execution Expression with Commands, Statements, and Constant input.
6 In the same manner, register "PINIT" as a User-Defined Function. Enter [PINIT] as the
function name and create the following script in Execution Expression.
7 In the same manner, register "Strset" as a User-Defined Function. Enter [Strset] as the
function name and create the following script in Execution Expression.
(1)
(2)
(3)
8 In the same manner, register "Print" as a User-Defined Function. Enter [Print] as the function
name and create the following script in Execution Expression.
9 Create the main script. Create the following script in Execution Expression and the settings
are complete.
• When placing the user-defined functions created in steps 3 to 9 into the main
script, select the function to be placed and click [Call] on the [Function] tab.
The function will be placed using "Call Function Name".
• When selecting text, press the [Ctrl] Key + [Shift] Key + [->] Key or [<-]
Key to select the entire text block.
• Press the [Ctrl] Key + [F4] Key to close the currently selected display.
• Press the [Esc] Key to overwrite the script or to delete and exit.
From the [Parts (P)] menu, select [D- From the [Common Settings (R)] menu,
Script (R)]. select [Global D-Script Settings (L)].
Set the trigger condition that causes the script to run. For more information about this
function, please refer to “20.7 Triggered Condition Setup” (page 20-46) .
Create the script (Execution Expression). For more information about commands and
functions, please refer to “21.13 Command List” (page 21-100) .
From the [Project (F)] menu, select [System Settings (C)]. Click [Script Settings]. The
following dialog box appears.
If using an extended script, set [Type] to [Extended Script] and select a [Port].
From the [Common Settings (R)] menu, select [Extended Script Settings (E)].
Create the script (Execution Expression). For more information about commands and
functions, please refer to “21 Commands and Descriptions” (page 21-1) .
Setting Procedure
When creating a new User-Defined Function
Click on [Create]. The User-Defined Function dialog box
appears.
Enter the function name and create the script in the Execution field. Click [OK] to save
the user-defined function.
• Restrictions apply to Function Names. For more information, see “20.9.3 Restrictions
on User-Defined Functions” (page 20-65) .
Select the user-defined function to call, click [Call] and "Call Function Name" will be
placed in the Execution field.
A created script can use any of the following 7 types of trigger conditions.
Setting Description
Continuous Action The script is triggered regularly.
Timer The script is triggered after a designated time elapses.
Bit Bit ON When the GP detects the designated bit rise from 0 to 1, the script is
triggered.
Bit OFF When the GP detects the falling edge of the designated bit, the script is
triggered.
Bit Change When the GP detects the designated bit rise from 0 to 1 or fall from 1 to
0, the script is triggered.
When When the GP detects true for a designated expression, the script is
Expression
Condition is triggered.
Condition
True
When When the GP detects false for a designated expression, the script is
Condition is triggered.
False
20.7.2 Timer
Timer
Each time the designated time elapses, the script is executed one time. The timer duration can
be set from 1 to 32,767 seconds.
t seconds t seconds
t [sec.]
Script processed Script processed
• When setting the timer function's time, the time value includes the set time +
display scan time error. Also, depending on the time taken to draw a screen
item or to printout data, the timer function may be slowed. For more
information about the Display Scan Time, please refer to “ Restrictions on
the Triggered Bit” (page 20-50) .
• When using D-Script, switching the screen causes the timer function to
restart counting from 0.
20.7.3 Bit
Bit ON
When the GP detects the designated bit address (trigger bit) rise from 0 to 1, the script is
triggered.
Triggered bit
• For the trigger bit's ON/OFF, make sure to leave an interval longer than the
communication cycle time or display scan time, whichever is longer. For
more information about this function, please refer to | “ Restrictions on the
Triggered Bit” (page 20-50) .
Bit OFF
When the GP detects the designated bit address (trigger bit) fall from 1 to 0, the script is
triggered.
Triggered bit
• For the trigger bit's ON/OFF, make sure to leave an interval longer than the
communication cycle time or display scan time, whichever is longer. For
more information about this function, please refer to “ Restrictions on the
Triggered Bit” (page 20-50) .
Bit Change
When the GP detects the designated bit address (trigger bit) rise from 0 to 1 or fall from 1 to
0, the script is triggered.
Triggered bit
• For the trigger bit's ON/OFF, make sure to leave an interval longer than the
communication cycle time or display scan time, whichever is longer. For
more information about this function, please refer to “ Restrictions on the
Triggered Bit” (page 20-50) .
• For the Triggered Condition, make sure to leave an interval longer than the
communication cycle time or display scan time, whichever is longer. For
more information about this function, please refer to “ Restrictions on the
Triggered Bit” (page 20-50) .
LS010000
Condition
Detect Trigger Detect Trigger Cannot Detect
Trigger
Value stored
during Triggered
operation
Read out Read out
[b:LS010000] [b:LS010000]
and store value and store value
of "1" of "1"
Read out Read out
[b:LS010000] [b:LS010000]
and store value and store value
of "0" of "1"
For example, if the D-Script touch timing is not used, and only detection is performed, the
processing is as follows.
When this type of D-Script is created, even if touch input is done repeatedly, the tag scan is
performed as shown in the following timing
chart. Here, each tag scan value is read out, the condition is compared and, regardless of the
previous value,
if it agrees with the condition, the processing is performed.
LS203800
Condition
LS010000
Condition
if ( ) statement
trigger
condition
Setting Description
Export This can be selected from the File menu. Export writes a created script to a
text file (.txt) which can then be imported into other scripts.
Import This can be selected from the File menu. Import reads in an exported script
(text file).
Row Shows the row number to the right of the program.
Number
Continued
GP-Pro EX Reference Manual 20-53
Settings Guide
Setting Description
Function Input When the function and the initial bracket "(" are inputted as below, the
Assistance function's format gets displayed.
Auto Syntax When "if" or "loop" is entered from the keypad, the remaining syntax is
Completion automatically placed.
Continued
Setting Description
Address When creating a script, enter a left square bracket ( [ ) to display the [Input
Input Address] dialog box.
Select the address type from [Bit Address], [Word Address], [Temporary
Address].
• Bit Address
You can specify the Device/PLC address, GP Internal Device and Bit
Variable.
• Word Address
You can specify the Device/PLC address, GP Internal Device and
Integer Variable.
• Temporary Address
This address can only be used for scripts.
Refer to the following for details on the internal device.
) “A.1.2 Communicating with a Device/PLC Using the Direct Access Method”
(page A-4)
) “A.1.3 Using the Memory Link Method with Unsupported Devices/PLCs” (page
A-6)
• In the scripts, please do NOT set any passwords, etc., that begin with
"0". All numeric values beginning with "0" will be processed as Oct
(base-8) data.
• How to describe different input data formats
For example,
DEC (Base- : Non-zero starting value
10) For example, 100
Hex (Base- : Value starting with 0x
16) For example, 0x100
Oct (Base-8) : Value starting with 0x
For example, 0100
• Example of operation with different data formats using the operator AND
(Hex and BCD)
Hex only
0x270F & Result: 0x2700
0xFF00
BCD and Hex
9999 & 0xFF00 Result: 0x9900
Continued
Setting Description
Auto Syntax Checks the syntax during script creation. The check results will be
Analysis displayed in the bottom portion of the window.
Continued
Setting Description
User Defined Register a script as a user-defined function and
Function it can be used by other scripts.
Setting Description
Call Call a created function. Select the function to call, click [Call] and "Call
Function Name" is placed in the Execution field.
Create Create a new function. Click on [Create]. The [Function Name] dialog box
appears.
Edit Edit an existing function. Select the function to edit, click on [Edit]. The
[D-Script Function] dialog box appears.
Delete Delete an existing function. Select the function to delete and click
[Delete].
Duplicate Copies the created function. Select the function to copy and click
[Duplicate] and when the [Input Function Name] dialog box appears, enter
the new function name.
Rename Change the name of an existing function. Click on [Rename]. The Rename
Function dialog box appears.
20.9 Restrictions
• In D-Script programming, three addresses occupy the same amount of memory as one
Part. The maximum number of addresses available for a D-Script is 255. Use the fewest
possible addresses, since the more devices that are used, the slower the response.
• The Convert Address feature cannot convert addresses used in D-Script. Open the D-
Script Editor to change these addresses.
• When the Connected Device Type settings are changed via the Project Manager menu >Project >
Save As, the address used by the D-Script cannot be changed. Use the D-Script Settings dialog
box to change the addresses.
• D-Script cannot run calculations on floating point values (Float Variables or Real
Variables) or structure variables. However, you can run calculations on individual
elements from structure variables.
• The size of a D-Script affects the Display Scan Time. Note that using a large number of
addresses may significantly degrade the program performance.
• Do not specify [Continuous Action] in the Trigger Conditions for the script to write to
device/PLC addresses. An error will be displayed because the communication processing
cannot keep up with the large amount of write instructions. To enable [Continuous
Action], use the GP internal device or temporary address.
• When calling a function within a function, the maximum number of nested levels is 9. Do
NOT create more than 9 levels.
• Up to 9 levels of nested calls can be created.
• Up to 254 Functions can be created.
Operation is performed immediately after the screen is changed, or the power is turned
ON.
Operation is not performed immediately after the screen is changed, or the power is
turned ON.
• When the timer is operating, the timer starts counting immediately after the screen
changes.
• When using Global D-Script, the operations mentioned above are performed only when
the GP power is turned ON. When the GP screen changes, however, the operation
mentioned above is not performed and the monitor operates using the trigger conditions
that have been set.
• When a Global D-Script includes a timer, the timer starts counting immediately after the
GP power is turned ON.
• Do not use the touch panel key to set the trigger bit or to operate the start bit
in a program. The timing of the touch input may not be correct, resulting in
the bit being improperly entered.
When data used for D-Scripts is set by touch from the GP, detect that all the
data has been written and then execute D-Scripts.
Restrictions Specific to Global D-Script
• When the GP power is turned ON, the actions shown in the table on the previous page are
performed. At the screen change, the above table is not applied, and the trigger conditions
are continuously monitored.
• Global D-Script operation is suspended during screen changes or other GP operations.
• After the GP power is turned ON, Global D-Script actions are not performed until all data
reads are completed for the initial screen. After the initial screen changes, Global D-Script
actions may be performed before the data reads are completed.
• The maximum number of devices in Global D-Scripts is 255. When this number is
exceeded, the D-Script does not function. Since these devices always read data regardless
of the screens, be sure to use only the minimum number of device settings in your D-
Script. Otherwise, operation performance can be degraded.
• The maximum number of Global D-Scripts available is 32. The currently used function
also counts as one Global D-Script. When the number of the Global D-Scripts reaches 32,
any subsequent Global D-Scripts are ignored.
• For Device Addresses, only the LS Area and USR Area (Extended User Area) can be
used.
• The temporary addresses of D-Scripts and Global D-Scripts are managed independently
from the temporary address of Extended Scripts. Therefore, changes made to the
temporary addresses of D-Scripts and Global D-Scripts are not reflected in the temporary
address of Extended Scripts.
• You can call user-defined functions created with D-Script/Global D-Script, but if you
access a device address outside of the internal device inside the function, it may not
operate normally. Also, when transferred (during the creation of data for the GP), user-
defined functions are created independently for D-Scripts, Global D-Scripts, and
Extended Scripts.
• When calling a function from a function, the maximum number of nested levels is 9.
• Up to 254 functions can be called. (The number of functions available with "Call" is 254.)
• Extended Script does not affect the tag count.
• Functions supported only by Extended Script, for example string operations, do not
function if called with D-Script or Global D-Script.
• The available data format is Bin. BCD data format is disabled.
• The size of the Send buffer is 2048 bytes, while the Receive buffer is 8192 bytes. The
CTS line is turned OFF after at least 80% of the Receive buffer is full of received data.
• General protocol and Extended Script cannot be selected simultaneously. The following
table shows more information about combinations.
• Portions of the commands that can be used differ with each script. When using
commands, please refer to “21.13 Command List” (page 21-100) .
• For the function name, you may use any English letters or the underscore character "_."
(However, the function name must begin with an alphanumeric character.)
• Do not use the following as Function Names.
Overflowing Digits
Overflowing digits resulting from operations are rounded.
When performing an operation on unsigned 16-bit data:
• 65535 + 1 = 0 (Produces overflowing digits)
• (65534 ∗ 2) / 2 = 32766 (Produces overflowing digits)
• (65534 / 2) ∗ 2 = 65534 (Does not produce overflowing digits)
20.9.5 Errors
The following error message is displayed when a Script is configured incorrectly. The error
will be displayed on the bottom of the GP screen.
Error codes are written to the LS91XX addresses. The number written in the error code area
will be the number portion following RAAA in the table below. (For example, when error
RAAA130 occurs, '130' will be written.)
List of Script Error Codes
D-Script Global D-Script Extended Script
(Error Address=LS9120) (Error Address=LS9110) (Error Address=LS9100)
- RAAA130 RAAA140
Unused Global D-Script Error. (The Extended D-Script Error
Total Number of Global D- (The total no. of functions
Scripts exceeds the maximum exceeds the max of 255.)
of 32.)
- RAAA131 -
Unused Global D-Script Error. (The Unused
total no. of devices exceeds
the maximum of 255.)
RAAA120 RAAA132 RAAA141
D-Script Error (The specified Global D-Script Error (The Extended D-Script Error
function does not exist or the specified function does not (The specified function does
function has an error.) exist or the function has an not exist or the function has
error.) an error.)
RAAA121 RAAA133 RAAA142
D-Script Error (These Global D-Script Error Extended D-Script Error
functions are nested to 10 (These functions are nested (These functions are nested to
levels or more.) to 10 levels or more.) 10 levels or more.)
RAAA122 RAAA134 RAAA143
D-Script Error (An Global D-Script Error (An Extended D-Script Error (An
expression exists, that is not expression exists, that is not expression exists, that is not
supported by this version.) supported by this version.) supported by this version.)
RAAA123 RAAA135 RAAA144
D-Script Error (The SIO Global D-Script Error (The Extended D-Script Error
operation function is used in SIO operation function is used (The SIO operation function
a condition where no device/ in a condition where no device/ is used in a condition where
PLC has been set.) PLC has been set.) no device/PLC has been set.)
RAAA124 RAAA136 RAAA145
The D-Script has an error. The Global D-script has an The Extended D-Script has
error. an error.