|
1 | 1 | # CSMScript-Lite |
2 | 2 |
|
3 | | -## 简介 |
| 3 | +[English](./README.md) | [中文](./README(zh-cn).md) |
4 | 4 |
|
5 | | -CSMScript-Lite 是一款基于 Communicable State Machine (CSM) 框架的脚本执行引擎,能够运行灵活的 CSM 测试脚本,实现自动化测试。同时,它也用于展示 CSM 框架的功能。其设计类似于 NI TestStand。 |
| 5 | +[](https://github.com/NEVSTOP-LAB/CSMScript-Lite/releases) |
6 | 6 |
|
7 | | -此项目包括: |
| 7 | +CSMScript-Lite is a lightweight script execution engine built on the [Communicable State Machine (CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine) framework. It executes flexible CSM-based test scripts to automate testing workflows, and also serves as a practical demonstration of CSM's capabilities. The design concept is similar to NI TestStand. |
8 | 8 |
|
9 | | -1. **CSMScript-Lite Library**:一个轻量级的 CSM 脚本执行引擎,它本身也是基于 CSM 实现的模块。 |
10 | | - - Engine:核心执行引擎,负责解析和执行 CSM 脚本,管理测试状态和结果。 |
11 | | - - UI:用户界面,提供脚本管理、执行控制和结果查看功能。 |
12 | | - - App:一个示例应用程序,展示如何使用 CSMScript 库进行脚本执行。 |
13 | | -3. **实例工程**:展示如何使用 CSMScript-Lite 配合其他 CSM 模块,实现脚本执行和自动化测试。 |
| 9 | +This project includes: |
| 10 | + |
| 11 | +- **CSMScript-Lite Library** — A lightweight CSM script execution engine, itself implemented as a CSM module. |
| 12 | + - **Engine**: Core execution engine that parses and runs CSM scripts, managing test state and results. |
| 13 | + - **UI**: User interface for script management, execution control, and result viewing. |
| 14 | + - **App**: A sample application demonstrating how to use the CSMScript library. |
| 15 | +- **Example Projects** — Demonstrate how to combine CSMScript-Lite with other CSM modules for script-driven automated testing. |
14 | 16 |
|
15 | 17 |  |
16 | 18 |
|
17 | | -## 依赖关系 |
| 19 | +## Dependencies |
18 | 20 |
|
19 | | -- LabVIEW 2020 及以上版本 |
20 | | -- NEVSTOP-LAB Palette |
21 | | -- Communicable State Machine (CSM) Framework |
22 | | - - Communicable State Machine(CSM) |
| 21 | +- LabVIEW 2020 or later |
| 22 | +- [Communicable State Machine (CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine) |
23 | 23 | - CSM API String Arguments Support |
24 | 24 | - CSM MassData Parameter Support |
25 | 25 | - CSM INI Static Variable Support |
26 | | -- NEVSTOP-Programming-Palette |
| 26 | +- NEVSTOP Programming Palette |
27 | 27 |
|
28 | | -## CSMScript-Lite Library 功能说明 |
| 28 | +## Features |
29 | 29 |
|
30 | | -### 基础功能:脚本执行 |
| 30 | +### Script Execution |
31 | 31 |
|
32 | | -支持 CSM 的全部命令,包括同步消息、异步消息、广播订阅等功能。详细的信息,请参考 CSM 框架的文档。 |
| 32 | +Supports all CSM commands, including sync messages, async messages, and broadcast/subscription. Refer to the [CSM documentation](https://github.com/NEVSTOP-LAB/Communicable-State-Machine) for full syntax details. |
33 | 33 |
|
34 | | -### 返回值保存传递 (Return Value) |
| 34 | +### Return Value Capture |
35 | 35 |
|
36 | | -通过 `=> 变量名` 语法,将指令的返回值保存到脚本的临时变量空间中,供后续指令使用。例如: |
| 36 | +Use the `=> varName` syntax to save a command's return value into the script's temporary variable space for use in subsequent commands: |
37 | 37 |
|
38 | 38 | ```c |
39 | 39 | message1 >> arguments -@ module1 => returnValueVar |
40 | 40 | message2 >> ${returnValueVar} -@ module2 |
41 | 41 | ``` |
42 | 42 |
|
43 | 43 | > [!NOTE] |
44 | | -> CSM - Run Script.vi 中也支持此功能,此处的功能与之相同。 |
45 | | -
|
46 | | -### 扩充指令 (Extended Commands) |
| 44 | +> This feature is also supported in `CSM - Run Script.vi` and behaves identically. |
47 | 45 |
|
48 | | -CSMScript 内置了一些非 CSM 提供的扩充指令,用于实现基本功能,如跳转指令等。 |
| 46 | +### Extended Commands |
49 | 47 |
|
50 | | -格式与 CSM 指令类似:`指令 >> 参数`,指令名称大小写不敏感。 |
| 48 | +CSMScript provides built-in commands beyond the standard CSM command set. The syntax follows the same pattern as CSM: `command >> arguments`. Command names are case-insensitive. |
51 | 49 |
|
52 | | -| 指令集名称 | 指令 | 说明 | |
53 | | -| --------------------- | ------------------------ | ------------------------------------------------------------ | |
54 | | -| 跳转指令 | GOTO | 跳转到指定的 `<anchor>` | |
55 | | -| 开启/关闭自动错误处理 | AUTO_ERROR_HANDLE_ENABLE | 开启或关闭自动错误处理功能 | |
56 | | -| 设置自动错误跳转锚点 | AUTO_ERROR_HANDLE_ANCHOR | 设置自动错误跳转的锚点,默认为 `<cleanup>` | |
57 | | -| 等待指令1 | WAIT, Sleep | 等待指定的时间,支持 minute(min)、second(s)、microsecond(ms) | |
58 | | -| 等待指令2 | WAIT(s), Sleep(s) | 等待指定的时间,单位为秒,参数为 Float 类型 | |
59 | | -| 等待指令3 | WAIT(ms), Sleep(ms) | 等待指定的时间,单位为毫秒,参数为 NUMERIC 类型 | |
| 50 | +| Category | Command | Description | |
| 51 | +|---|---|---| |
| 52 | +| Jump | `GOTO` | Jump to the specified `<anchor>` | |
| 53 | +| Auto Error Handling | `AUTO_ERROR_HANDLE_ENABLE` | Enable or disable automatic error handling | |
| 54 | +| Auto Error Anchor | `AUTO_ERROR_HANDLE_ANCHOR` | Set the error jump anchor (default: `<cleanup>`) | |
| 55 | +| Wait | `WAIT`, `Sleep` | Wait for a specified duration; supports `min`, `s`, and `ms` units in one expression | |
| 56 | +| Wait (seconds) | `WAIT(s)`, `Sleep(s)` | Wait for a float number of seconds | |
| 57 | +| Wait (milliseconds) | `WAIT(ms)`, `Sleep(ms)` | Wait for an integer number of milliseconds | |
60 | 58 |
|
61 | | -举例: |
| 59 | +Examples: |
62 | 60 |
|
63 | 61 | ```c |
64 | 62 | message1 >> arguments -@ csm |
65 | | -wait >> 1min 20s 500ms // 等待 1 分 20 秒 500 毫秒 |
| 63 | +wait >> 1min 20s 500ms // wait 1 minute, 20 seconds, and 500 milliseconds |
66 | 64 |
|
67 | 65 | message1 >> arguments -@ csm |
68 | | -wait(ms) >> 100 // 等待 100 毫秒 |
| 66 | +wait(ms) >> 100 // wait 100 milliseconds |
69 | 67 |
|
70 | 68 | message1 >> arguments -@ csm |
71 | | -wait(s) >> 1.5 // 等待 1.5 秒 |
| 69 | +wait(s) >> 1.5 // wait 1.5 seconds |
72 | 70 | ``` |
73 | 71 |
|
74 | | -### 锚点跳转 (Anchor) |
75 | | - |
76 | | -支持在脚本中定义锚点,并通过错误跳转或变量逻辑判断跳转到指定锚点继续执行脚本。 |
| 72 | +### Anchors and Jumps |
77 | 73 |
|
78 | | -- **锚点定义格式**:`<anchor_name>`,例如 `<setup>`、`<main>`、`<error_handler>`、`<cleanup>` 等,大小写不敏感。 |
79 | | -- **锚点跳转格式**:`?? goto >> <anchor_name>` 语法,在指令执行错误时跳转到指定锚点继续执行脚本。缺省 expression 表示指令执行错误时跳转。 |
| 74 | +Scripts can define named anchors and jump to them on error or via explicit `GOTO` commands. |
80 | 75 |
|
81 | | -`AUTO_ERROR_HANDLE_ANCHOR` 指令可以设置自动错误跳转的锚点,缺省为 `<cleanup>`。 |
| 76 | +- **Anchor definition**: `<anchor_name>` — e.g., `<setup>`, `<main>`, `<error_handler>`, `<cleanup>`. Names are case-insensitive. |
| 77 | +- **Conditional jump**: `?? goto >> <anchor_name>` — jumps to the anchor if the preceding command produced an error. Omitting the condition expression means "on any error." |
82 | 78 |
|
83 | | -`AUTO_ERROR_HANDLE_ENABLE` 指令可以开启自动错误处理功能,当指令执行错误时,自动跳转到预设的锚点继续执行脚本。 |
| 79 | +`AUTO_ERROR_HANDLE_ANCHOR` sets the default error-jump anchor (default: `<cleanup>`). |
| 80 | +`AUTO_ERROR_HANDLE_ENABLE` turns on automatic error handling so that any failing command automatically jumps to the preset anchor. |
84 | 81 |
|
85 | | -例如: |
| 82 | +Example: |
86 | 83 |
|
87 | 84 | ```c |
88 | | -// 开启自动错误处理 |
| 85 | +// Enable automatic error handling |
89 | 86 | AUTO_ERROR_HANDLE_ENABLE >> TRUE |
90 | | -// 设置自动错误跳转锚点为 error_handler,不再使用 cleanup 作为默认锚点 |
| 87 | +// Override default error anchor to error_handler |
91 | 88 | AUTO_ERROR_HANDLE_ANCHOR >> error_handler |
92 | 89 |
|
93 | 90 | <setup> // ----- setup anchor ---- |
94 | 91 |
|
95 | | -// 逻辑上,初始化失败,无需执行 stop 指令, |
96 | | -// 所以这里显式添加了错误时跳转到 cleanup 锚点, |
97 | | -// 当此指令执行失败时,将跳转到 cleanup 锚点 |
| 92 | +// Initialization failure should skip "stop", so jump directly to cleanup on error |
98 | 93 | initialize >> daq1 -@ ai ?? goto >> <cleanup> |
99 | 94 |
|
100 | 95 | <main> // ----- main anchor ---- |
101 | 96 |
|
102 | | -// 之后的所有指令,如果执行失败,都将跳转到 error_handler 锚点 |
| 97 | +// All subsequent commands jump to error_handler on failure |
103 | 98 | configure >> Onboard Clock;10,-10,RSE -@ ai |
104 | | - |
105 | 99 | start -@ ai |
106 | | - |
107 | 100 | acquire >> Channel:ch0;Num:1000 -@ ai |
108 | 101 |
|
109 | 102 | <error_handler> // ----- error handler anchor ---- |
110 | 103 | stop -@ ai |
111 | 104 |
|
112 | | -<cleanup> //----- cleanup anchor ---- |
| 105 | +<cleanup> // ----- cleanup anchor ---- |
113 | 106 | close -@ ai |
114 | | - |
115 | 107 | ``` |
116 | 108 |
|
117 | 109 | > [!NOTE] |
118 | | -> 默认的情况下,自动错误处理的是不打开的,需要通过 `AUTO_ERROR_HANDLE_ENABLE` 指令开启。 |
119 | | -> 此时当发生错误时,将继续执行之后的指令。 |
| 110 | +> Automatic error handling is **disabled by default**. Enable it with `AUTO_ERROR_HANDLE_ENABLE >> TRUE`. Without it, execution continues to the next command even after an error. |
120 | 111 |
|
121 | 112 | > [!NOTE] |
122 | | -> 最常见的锚点主要用于定义脚本运行阶段,例如可以定义类似 TestStand 序列的 `<setup>`, `<main>`, `<cleanup>` 等锚点。 |
| 113 | +> Anchors are most commonly used to define script phases, similar to the `<setup>`, `<main>`, and `<cleanup>` sequence stages in NI TestStand. |
123 | 114 |
|
124 | 115 | > [!NOTE] |
125 | | -> GOTO 指令和 AUTO_ERROR_HANDLE_ANCHOR 指令参数中可以携带 <> 符号,也可以不携带,例如 `GOTO >> cleanup` 和 `GOTO >> <cleanup>` 效果相同。 |
| 116 | +> The `<>` brackets in anchor names are optional. `GOTO >> cleanup` and `GOTO >> <cleanup>` are equivalent. |
0 commit comments