| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
IDEC-TUI includes a small scripting language for automating PLC commands.
The goal is not to create a general-purpose programming language. The scripting system is intended for PLC testing, commissioning, diagnostics, repetitive operations, and simple automated control tasks using the same commands available from the IDEC-TUI console.
Scripts are plain-text files and are executed from the IDEC-TUI prompt with:
run test.plc
The .plc extension is used in the examples for clarity, but scripts are simply text files.
# Write and verify a register
echo Writing 690 to D100
write D100 690
read D100
if read D100 == 690
print D100 was written successfully
else
print D100 did not contain the expected value
end
Run it from IDEC-TUI:
plc[connected]> run test.plc
Most commands that work from the IDEC-TUI console can also be used from a script.
For example:
read D100
write D100 42
read_bit Y0030
write_bit M0000 1
input I0
output Q0030 1
read_float D200
write_float D200 12.5
force Q3 1
Commands exposed by MiSmSerial may also be available through the TUI.
Because scripts use the same command dispatcher as the interactive console, improvements to the PLC command interface generally become available to scripts automatically.
Whole-line comments begin with #.
# This is a comment
write D100 100
# Read the value back
read D100
Whitespace before the comment is allowed:
# This is also a comment
Inline comments are currently not recommended.
Do not write:
output Q0030 1 # Turn output on
Some script parsing recognizes #, but ordinary PLC commands are ultimately passed through the regular TUI command parser, where the remainder of the line may be interpreted as arguments.
Use:
# Turn output on
output Q0030 1
Scripts can display human-readable information using either:
print
or:
echo
Examples:
print Starting output test
echo Testing expansion module
Quoted strings are also accepted:
print "Starting output test"
echo "Writing 690 to D100"
The quotes are not printed.
Output:
Starting output test
Writing 690 to D100
Printing messages is useful for making test scripts easier to follow:
echo Turning Q0030 ON
output Q0030 1
sleep 1
echo Turning Q0030 OFF
output Q0030 0
Use sleep to pause script execution.
sleep 1
Fractional seconds may also be used:
sleep 0.5
Example:
output Q0030 1
sleep 0.5
output Q0030 0
The basic loop syntax is:
for variable start stop
commands
end
The ending value is included.
Example:
for i 1 5
print Loop $i
end
The loop variable is referenced using $.
Output:
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5
Cycle outputs Q0030 through Q0037:
for q 30 37
echo Turning Q00$q ON
output Q00$q 1
sleep 0.5
echo Turning Q00$q OFF
output Q00$q 0
end
When q is 30:
Q00$q
becomes:
Q0030
Loops may also count downward.
for q 37 30
echo Testing Q00$q
output Q00$q 1
sleep 0.25
output Q00$q 0
end
This tests:
Q0037
Q0036
Q0035
...
Q0030
For loops may be nested.
for cycle 1 3
echo Starting cycle $cycle
for q 30 37
echo Testing Q00$q
output Q00$q 1
sleep 0.25
output Q00$q 0
end
end
This cycles outputs Q0030 through Q0037 three times.
Each loop has its own variable:
$cycle
$q
Scripts support if, else, and end.
Basic syntax:
if command operator value
commands
else
commands
end
Example:
if read D100 > 250
print D100 is above 250
else
print D100 is 250 or below
end
The else block is optional:
if read D100 == 690
print D100 contains the expected value
end
The following comparison operators are supported:
==
!=
<
<=
>
>=
Examples:
if read D100 == 100
print Equal
end
if read D100 != 0
print D100 is not zero
end
if read D100 >= 500
print D100 reached 500
end
Bit reads can also be used as conditions.
if read_bit Y0030 == 1
print Output Y0030 is ON
else
print Output Y0030 is OFF
end
For PLC outputs, the underlying PLC bit type is currently Y.
For example:
output Q0030 1
read_bit Y0030
Q is accepted by the high-level output command, while read_bit currently uses the native PLC bit type.
Conditionals may be nested.
if read D100 > 250
if read D100 == 690
print D100 is exactly 690
else
print D100 is above 250 but is not 690
end
else
print D100 is 250 or below
end
Loops and conditionals can be combined.
for q 30 37
echo Testing Q00$q
output Q00$q 1
sleep 0.25
if read_bit Y00$q == 1
print Output state is ON
else
print Output state did not turn ON
end
output Q00$q 0
end
This makes it possible to create compact PLC hardware test scripts.
return is intended to stop execution of the current script and return control to the IDEC-TUI console.
Example:
write D100 690
if read D100 == 690
print Test complete
return
end
print This line only executes if the script did not return
After return, control should return to:
plc[connected]>
return is different from:
exit
exit, quit, and q are IDEC-TUI commands and terminate the entire terminal application.
The intended meanings are:
return Stop the current script
exit Exit IDEC-TUI
quit Exit IDEC-TUI
q Exit IDEC-TUI
# Register write/read test
echo Writing 690 to D100
write D100 690
echo Reading D100
read D100
if read D100 == 690
print PASS - D100 contains 690
else
print FAIL - D100 does not contain 690
end
# Cycle expansion outputs
echo Starting output test
for cycle 1 3
echo Starting cycle $cycle
for q 30 37
echo Turning Q00$q ON
output Q00$q 1
sleep 0.5
echo Turning Q00$q OFF
output Q00$q 0
sleep 0.25
end
end
echo Output test complete
echo Checking D100
if read D100 > 250
echo D100 is above the limit
output Q0030 1
else
echo D100 is below the limit
output Q0030 0
end
echo Starting register test
write D100 690
if read D100 > 250
if read D100 == 690
print D100 is exactly 690
print Test finished early
return
end
print D100 is above 250
end
print Continuing with remaining tests
IDEC-TUI scripts deliberately reuse the normal terminal command interface.
For example, the interactive command:
plc[connected]> read D100
can be placed directly into a script:
read D100
This keeps the scripting language small and avoids creating a separate PLC API specifically for scripts.
The scripting layer primarily adds control-flow features around normal IDEC-TUI commands:
for
if
else
end
sleep
print
echo
return
The scripting language is intentionally small and is still under development.
Currently, it does not provide a full general-purpose programming environment.
Notable limitations include:
Loop variables are currently the primary scripting variables.
For example:
for q 30 37
print $q
end
Useful future additions may include:
set
break
continue
while
wait
assert
quiet
For example, a future assert command could make automated hardware validation possible:
output Q0030 1
sleep 0.25
assert read_bit Y0030 == 1
A future wait command could provide timeout-based PLC sequencing:
output Q0030 1
wait input I0 == 1 timeout 5
These features are not part of the current scripting syntax unless explicitly implemented.
IDEC-TUI can directly write PLC registers and control physical outputs.
A script such as:
output Q0030 1
may energize real equipment.
Before running a script:
The IDEC-TUI scripting language is intentionally simple.
The goal is to make tasks such as this easy:
for q 30 37
print Testing Q00$q
output Q00$q 1
sleep 0.5
output Q00$q 0
end
without requiring a separate Python program for every repetitive PLC test.
IDEC-TUI provides the PLC commands.
The scripting layer provides just enough logic to automate them.
Call a script from a script
# a.plc
echo a.plc
run b.plc
# b.plc
echo hello from b.plc
which means you can make an infinte loop and other whacky BS, provided a.plc and b.plc both exist
| Back | FazBrowse Home | New Git URL |