Skip to content

Commit b3f33f2

Browse files
Copilotnevstop
andcommitted
Sync and rewrite README: add English README.md, create Chinese README(zh-cn).md
Agent-Logs-Url: https://github.com/NEVSTOP-LAB/CSMScript-Lite/sessions/dcd4976b-e500-4f63-a613-757a664c7338 Co-authored-by: nevstop <8196752+nevstop@users.noreply.github.com>
1 parent e79d0c6 commit b3f33f2

2 files changed

Lines changed: 165 additions & 58 deletions

File tree

‎README(zh-cn).md‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# CSMScript-Lite
2+
3+
[English](./README.md) | [中文](./README(zh-cn).md)
4+
5+
[![GitHub all releases](https://img.shields.io/github/downloads/NEVSTOP-LAB/CSMScript-Lite/total)](https://github.com/NEVSTOP-LAB/CSMScript-Lite/releases)
6+
7+
CSMScript-Lite 是一款基于 [可通信状态机(CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine) 框架的轻量级脚本执行引擎,用于执行灵活的 CSM 测试脚本,实现自动化测试工作流。同时,它也是展示 CSM 框架能力的实践示例。其设计理念类似于 NI TestStand。
8+
9+
此项目包括:
10+
11+
- **CSMScript-Lite Library** — 轻量级 CSM 脚本执行引擎,其本身也是一个基于 CSM 实现的模块。
12+
- **Engine**:核心执行引擎,负责解析并运行 CSM 脚本,管理测试状态与结果。
13+
- **UI**:用户界面,提供脚本管理、执行控制和结果查看功能。
14+
- **App**:示例应用程序,展示如何使用 CSMScript 库执行脚本。
15+
- **实例工程** — 展示如何将 CSMScript-Lite 与其他 CSM 模块结合,实现脚本驱动的自动化测试。
16+
17+
![CSMScriptApp](.github/CSMScript%20UI.png)
18+
19+
## 依赖
20+
21+
- LabVIEW 2020 及以上版本
22+
- [Communicable State Machine (CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine)
23+
- CSM API String Arguments Support
24+
- CSM MassData Parameter Support
25+
- CSM INI Static Variable Support
26+
- NEVSTOP Programming Palette
27+
28+
## 功能说明
29+
30+
### 脚本执行
31+
32+
支持全部 CSM 命令,包括同步消息、异步消息、广播订阅等。完整语法请参考 [CSM 框架文档](https://github.com/NEVSTOP-LAB/Communicable-State-Machine)。
33+
34+
### 返回值捕获
35+
36+
通过 `=> 变量名` 语法,将指令的返回值保存到脚本临时变量空间中,供后续指令使用:
37+
38+
```c
39+
message1 >> arguments -@ module1 => returnValueVar
40+
message2 >> ${returnValueVar} -@ module2
41+
```
42+
43+
> [!NOTE]
44+
> `CSM - Run Script.vi` 中同样支持此语法,行为完全一致。
45+
46+
### 扩充指令
47+
48+
CSMScript 内置了一套超出标准 CSM 命令集的扩充指令,语法与 CSM 指令相同:`指令 >> 参数`,指令名称大小写不敏感。
49+
50+
| 类别 | 指令 | 说明 |
51+
|---|---|---|
52+
| 跳转 | `GOTO` | 跳转到指定的 `<anchor>` |
53+
| 自动错误处理 | `AUTO_ERROR_HANDLE_ENABLE` | 开启或关闭自动错误处理 |
54+
| 自动错误锚点 | `AUTO_ERROR_HANDLE_ANCHOR` | 设置错误跳转锚点(默认:`<cleanup>`) |
55+
| 等待 | `WAIT`、`Sleep` | 等待指定时长,支持在一个表达式中混合使用 `min`、`s`、`ms` |
56+
| 等待(秒) | `WAIT(s)`、`Sleep(s)` | 等待指定秒数,参数为浮点类型 |
57+
| 等待(毫秒) | `WAIT(ms)`、`Sleep(ms)` | 等待指定毫秒数,参数为整数类型 |
58+
59+
示例:
60+
61+
```c
62+
message1 >> arguments -@ csm
63+
wait >> 1min 20s 500ms // 等待 1 分 20 秒 500 毫秒
64+
65+
message1 >> arguments -@ csm
66+
wait(ms) >> 100 // 等待 100 毫秒
67+
68+
message1 >> arguments -@ csm
69+
wait(s) >> 1.5 // 等待 1.5 秒
70+
```
71+
72+
### 锚点与跳转
73+
74+
脚本中可定义命名锚点,并通过错误跳转或显式 `GOTO` 跳转到指定锚点继续执行。
75+
76+
- **锚点定义**:`<anchor_name>`,例如 `<setup>`、`<main>`、`<error_handler>`、`<cleanup>`,大小写不敏感。
77+
- **条件跳转**:`?? goto >> <anchor_name>`,在前一条指令出错时跳转到指定锚点。省略条件表达式等同于"任意错误时跳转"。
78+
79+
`AUTO_ERROR_HANDLE_ANCHOR` 指令设置默认的错误跳转锚点(默认为 `<cleanup>`)。
80+
`AUTO_ERROR_HANDLE_ENABLE` 指令开启自动错误处理,任何指令执行失败时,自动跳转到预设锚点。
81+
82+
示例:
83+
84+
```c
85+
// 开启自动错误处理
86+
AUTO_ERROR_HANDLE_ENABLE >> TRUE
87+
// 将默认错误锚点改为 error_handler
88+
AUTO_ERROR_HANDLE_ANCHOR >> error_handler
89+
90+
<setup> // ----- setup anchor ----
91+
92+
// 初始化失败不需要执行 stop,因此显式指定跳转到 cleanup
93+
initialize >> daq1 -@ ai ?? goto >> <cleanup>
94+
95+
<main> // ----- main anchor ----
96+
97+
// 之后的所有指令,执行失败时将跳转到 error_handler
98+
configure >> Onboard Clock;10,-10,RSE -@ ai
99+
start -@ ai
100+
acquire >> Channel:ch0;Num:1000 -@ ai
101+
102+
<error_handler> // ----- error handler anchor ----
103+
stop -@ ai
104+
105+
<cleanup> // ----- cleanup anchor ----
106+
close -@ ai
107+
```
108+
109+
> [!NOTE]
110+
> 自动错误处理**默认关闭**,需通过 `AUTO_ERROR_HANDLE_ENABLE >> TRUE` 显式开启。未开启时,指令执行出错后将继续执行下一条指令。
111+
112+
> [!NOTE]
113+
> 锚点最常见的用途是划分脚本执行阶段,类似于 NI TestStand 序列中的 `<setup>`、`<main>`、`<cleanup>` 等阶段。
114+
115+
> [!NOTE]
116+
> 锚点名称中的 `<>` 符号可省略,`GOTO >> cleanup` 与 `GOTO >> <cleanup>` 效果相同。

‎README.md‎

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,116 @@
11
# CSMScript-Lite
22

3-
## 简介
3+
[English](./README.md) | [中文](./README(zh-cn).md)
44

5-
CSMScript-Lite 是一款基于 Communicable State Machine (CSM) 框架的脚本执行引擎,能够运行灵活的 CSM 测试脚本,实现自动化测试。同时,它也用于展示 CSM 框架的功能。其设计类似于 NI TestStand。
5+
[![GitHub all releases](https://img.shields.io/github/downloads/NEVSTOP-LAB/CSMScript-Lite/total)](https://github.com/NEVSTOP-LAB/CSMScript-Lite/releases)
66

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.
88

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.
1416

1517
![CSMScriptApp](.github/CSMScript%20UI.png)
1618

17-
## 依赖关系
19+
## Dependencies
1820

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)
2323
- CSM API String Arguments Support
2424
- CSM MassData Parameter Support
2525
- CSM INI Static Variable Support
26-
- NEVSTOP-Programming-Palette
26+
- NEVSTOP Programming Palette
2727

28-
## CSMScript-Lite Library 功能说明
28+
## Features
2929

30-
### 基础功能:脚本执行
30+
### Script Execution
3131

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.
3333

34-
### 返回值保存传递 (Return Value)
34+
### Return Value Capture
3535

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:
3737

3838
```c
3939
message1 >> arguments -@ module1 => returnValueVar
4040
message2 >> ${returnValueVar} -@ module2
4141
```
4242
4343
> [!NOTE]
44-
> CSM - Run Script.vi 中也支持此功能,此处的功能与之相同。
45-
46-
### 扩充指令 (Extended Commands)
44+
> This feature is also supported in `CSM - Run Script.vi` and behaves identically.
4745
48-
CSMScript 内置了一些非 CSM 提供的扩充指令,用于实现基本功能,如跳转指令等。
46+
### Extended Commands
4947
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.
5149
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 |
6058
61-
举例:
59+
Examples:
6260
6361
```c
6462
message1 >> arguments -@ csm
65-
wait >> 1min 20s 500ms // 等待 1 分 20 秒 500 毫秒
63+
wait >> 1min 20s 500ms // wait 1 minute, 20 seconds, and 500 milliseconds
6664
6765
message1 >> arguments -@ csm
68-
wait(ms) >> 100 // 等待 100 毫秒
66+
wait(ms) >> 100 // wait 100 milliseconds
6967
7068
message1 >> arguments -@ csm
71-
wait(s) >> 1.5 // 等待 1.5 秒
69+
wait(s) >> 1.5 // wait 1.5 seconds
7270
```
7371

74-
### 锚点跳转 (Anchor)
75-
76-
支持在脚本中定义锚点,并通过错误跳转或变量逻辑判断跳转到指定锚点继续执行脚本。
72+
### Anchors and Jumps
7773

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.
8075

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."
8278

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.
8481

85-
例如:
82+
Example:
8683

8784
```c
88-
// 开启自动错误处理
85+
// Enable automatic error handling
8986
AUTO_ERROR_HANDLE_ENABLE >> TRUE
90-
// 设置自动错误跳转锚点为 error_handler,不再使用 cleanup 作为默认锚点
87+
// Override default error anchor to error_handler
9188
AUTO_ERROR_HANDLE_ANCHOR >> error_handler
9289

9390
<setup> // ----- setup anchor ----
9491

95-
// 逻辑上,初始化失败,无需执行 stop 指令,
96-
// 所以这里显式添加了错误时跳转到 cleanup 锚点,
97-
// 当此指令执行失败时,将跳转到 cleanup 锚点
92+
// Initialization failure should skip "stop", so jump directly to cleanup on error
9893
initialize >> daq1 -@ ai ?? goto >> <cleanup>
9994

10095
<main> // ----- main anchor ----
10196

102-
// 之后的所有指令,如果执行失败,都将跳转到 error_handler 锚点
97+
// All subsequent commands jump to error_handler on failure
10398
configure >> Onboard Clock;10,-10,RSE -@ ai
104-
10599
start -@ ai
106-
107100
acquire >> Channel:ch0;Num:1000 -@ ai
108101

109102
<error_handler> // ----- error handler anchor ----
110103
stop -@ ai
111104

112-
<cleanup> //----- cleanup anchor ----
105+
<cleanup> // ----- cleanup anchor ----
113106
close -@ ai
114-
115107
```
116108

117109
> [!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.
120111
121112
> [!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.
123114
124115
> [!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

Comments
 (0)