
45
2.0 Getting Started
2.10 Link*One Scripting
2.10.1 Overview
Link*One has an embedded script language called Lua. When Link*One
receives data from a device, a hot key is pressed etc. certain methods in
the script are called. The code in these scripts determines what action
is taken.
The name of the script file is Script.txt and is placed in the Link*One
application data folder. The location of this folder varies depending on
what operating system you are using. If you need to make a backup of
the script or copy it to another PC, click on the Browse Script Folder...
on the Misc tab in the Settings dialog. Windows Explorer is opened and
displays the contents of the script folder.
When you edit the script, remember to restart Link*One to recompile
the script or use the faster alternative of entering the Settings dialog and
then exiting it.
If you make a mistake, for example create a syntax error, an error mes-
sage is displayed when the script is compiled:
Also, some errors can appear when the script is running, so called run-
time errors. Here are a couple of examples:
2.10.2
Lua Language
From
http://www.lua.org/about.html
:
Lua is a powerful, fast, light-weight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description
constructs based on associative arrays and extensible semantics.
Put simply, Lua is what makes data processing in Link*One very flexible
and powerful. The reference manual for Lua can be found at the Lua site:
http://www.lua.org/
There is also a printed book on the Lua language, called Programming
in Lua, which is more accessible than the reference manual.
Apart from Lua and its built-in language, Link*One exposes a number
of useful methods to the script.
2.10.3
Script Events
When things happen in Link*One, for example a hot key or a data string
is received on the serial port, an event is generated. This results in a
script method being called. The methods called when events happen are
called event methods.
The table below is an overview and short description of all the differ-
ent event methods. For a more detailed explanation, see the topic Event
Methods below.
Event Handler
When Called
onStart
Link*One is started
onEnd
Link*One is exited
onData
A data string is received on the serial port
onHotKey
A hot key is pressed
onKeyboardCapture
A data string is received from a HID device
onExternalData
A data string is received from an external
application
onTimer
The timer interval has elapsed
onCTS
Status change on CTS
onDSR
Status change on DTR
onRI
Status change on RI
onDCD
Status change on DCD
2.10.4
Event Methods
In this topic all the event methods are explained in detail.
2.10.4.1 onStart()
This method is called when Link*One is started. It is also called when
you exit the
Settings
dialog.
This method receives no arguments.
Example: Beep on start
2.10.4.2 onEnd()
Called when Link*One is exited. It is also called when you enter the
Settings
dialog.
This method receives no arguments.
Example: Beep on exit
2.10.4.3 onData(data, length)
Called when a data string is received from the serial port.
This method receives the data string in data and the length of the string
in length.
Data may contain binary characters including the null character.
Please note that if the
Data String Termination
is set to be a charac-
ter and that character does not match the terminator used by the serial
device, this method is never called.