Scripting
TLDR: Using the embedded YOS/shell
interpreter, every siliXcon device provides the ability to execute scripts.
With the script, you can enhance the functionality, automate some tasks, or even create your own application.
The source code of the script is either:
- permanently installed inside the device's FLASH memory and executed automatically after a successful boot. The YOS command
script
serves to manage the internal persistent script. To learn more, check the persistent script tutorial. - parsed from the stream input during run-time. The device usually provides multiple means of ASCII stream input/output forwarding. The tool
term
is typically used to provide the CLI environment, mainlyYOS/shell
. Check the term's scripting tutorial for examples. Nevertheless, even without any siliXcon software, you can use a generic serial terminal hooked up to one of the managed USARTs to access the CLI, the interpreter and enter scripts.
YOS Scripting was developed for in-application testing: controller/motor/drivetrain/battery evaluation, however, you may use it for anything else. A script is a set of structured text commands, which is executed in the device.
- The scripts are executed in the device's MCU, not on the host PC.
- The preprocessing directives only work if the script is loaded using term.
Quick example
As mentioned above, the term
offers the ability to load scripts to the device during run-time.
To execute a script, make sure that you have a connected device. Save the script with .ys extension and double-click on the file. The script will be loaded inside the device and output will be shown in the console window.
For large files, the tool ensures proper flow control (it is not advised to terminate the 'term' tool when a script is running).
A line beginning with '@' signifies a preprocessing directive. Such a line will not be sent to the device but processed inside the term
tool (e.g. automatic login). For more info, please refer to the term manual.
@! # automatic login
# Print value of variable
echo Iref before: $/driver/iref A
# Set the value of the variable
set /driver/iref 50
echo Iref after: $/driver/iref A
if (/driver/error <0) {
echo Driver is not initialized
echo Error: $/driver/error
}
The output of this example looks like this:
- More examples come with the SWTools installation package and can be found in the folder:
C:\silixcon\scripts\
- Yet more, developer-related examples and unit tests can be found in our GitHub repository.