Scripting Overview
SerialStudio can be extended with scripts in two places. Both support Lua 5.4 and Python 3.13:
| Checksum script | Frame processing script | |
|---|---|---|
| Purpose | Compute the checksum of HEX data you send | Transform every frame you receive |
| Entry function | calculate_checksum(data) | process_frame(data) |
| Where in the UI | The Checksum drop-down in the send area | The Frame Processing (帧处理) drop-down in the receive area |
| When it runs | When sending in HEX mode, before the data is sent | After received data is split into packets and before it is displayed |
| Python argument | Byte data (convert it with bytes(data) first) | bytes |
| Lua argument | An array of integers (a table, indexed from 1) | A string (raw bytes, may contain \0) |
| Is the script kept loaded | No, the script is reloaded for every calculation | Yes, it is loaded once and global variables persist between frames |
| When the script fails | The send fails and the error is shown in the receive box | The failing frame is dropped and the error is shown in the receive box |
The argument types differ
In Lua, a checksum script receives an array of integers, while a frame processing script receives a string. The entry functions of the two kinds of script are not interchangeable.
Choosing a script type
- To append a checksum that the built-in algorithms do not provide to the data you send, use a checksum script.
- To rewrite received data before it is displayed or saved, for example to strip headers and trailers, decode it, or filter heartbeat packets, use a frame processing script.
Common rules
- Script files must be UTF-8 encoded. Lua scripts use the
.luaextension and Python scripts use.py. - The entry function name must match the table above exactly. Otherwise loading the script fails with a "function not found" message.
- After you pick a script, the program loads and checks it first, and enables it only if the check passes. When the check fails, the reason is printed in the receive box.
