Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added App/Launcher.vi
Binary file not shown.
File renamed without changes.
File renamed without changes.
163 changes: 81 additions & 82 deletions CSMStand-Lite.lvproj → CSMScript-Lite.lvproj

Large diffs are not rendered by default.

Binary file removed CSMStand(Lite)/Engine/_Support/Internal Operation.vi
Binary file not shown.
Binary file not shown.
Binary file removed CSMStand(Lite)/UI/Support/Sequence-DefaultStyle.vi
Binary file not shown.
Binary file removed CSMStand(Lite)/UI/VersionDialog(CSM).vi
Binary file not shown.
Binary file removed CSMStandApp/Launcher.vi
Binary file not shown.
116 changes: 116 additions & 0 deletions README(zh-cn).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# CSMScript-Lite

[English](./README.md) | [中文](./README(zh-cn).md)

[![GitHub all releases](https://img.shields.io/github/downloads/NEVSTOP-LAB/CSMScript-Lite/total)](https://github.com/NEVSTOP-LAB/CSMScript-Lite/releases)

CSMScript-Lite 是一款基于 [可通信状态机(CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine) 框架的轻量级脚本执行引擎,用于执行灵活的 CSM 测试脚本,实现自动化测试工作流。同时,它也是展示 CSM 框架能力的实践示例。其设计理念类似于 NI TestStand。

此项目包括:

- **CSMScript-Lite Library** — 轻量级 CSM 脚本执行引擎,其本身也是一个基于 CSM 实现的模块。
- **Engine**:核心执行引擎,负责解析并运行 CSM 脚本,管理测试状态与结果。
- **UI**:用户界面,提供脚本管理、执行控制和结果查看功能。
- **App**:示例应用程序,展示如何使用 CSMScript 库执行脚本。
- **实例工程** — 展示如何将 CSMScript-Lite 与其他 CSM 模块结合,实现脚本驱动的自动化测试。

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

## 依赖

- LabVIEW 2020 及以上版本
- [Communicable State Machine (CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine)
- CSM API String Arguments Support
- CSM MassData Parameter Support
- CSM INI Static Variable Support
- NEVSTOP Programming Palette

## 功能说明

### 脚本执行

支持全部 CSM 命令,包括同步消息、异步消息、广播订阅等。完整语法请参考 [CSM 框架文档](https://github.com/NEVSTOP-LAB/Communicable-State-Machine)。

### 返回值捕获

通过 `=> 变量名` 语法,将指令的返回值保存到脚本临时变量空间中,供后续指令使用:

```c
message1 >> arguments -@ module1 => returnValueVar
message2 >> ${returnValueVar} -@ module2
```

> [!NOTE]
> `CSM - Run Script.vi` 中同样支持此语法,行为完全一致。

### 扩充指令

CSMScript 内置了一套超出标准 CSM 命令集的扩充指令,语法与 CSM 指令相同:`指令 >> 参数`,指令名称大小写不敏感。

| 类别 | 指令 | 说明 |
|---|---|---|
| 跳转 | `GOTO` | 跳转到指定的 `<anchor>` |
| 自动错误处理 | `AUTO_ERROR_HANDLE_ENABLE` | 开启或关闭自动错误处理 |
| 自动错误锚点 | `AUTO_ERROR_HANDLE_ANCHOR` | 设置错误跳转锚点(默认:`<cleanup>`) |
| 等待 | `WAIT`、`Sleep` | 等待指定时长,支持在一个表达式中混合使用 `min`、`s`、`ms` |
| 等待(秒) | `WAIT(s)`、`Sleep(s)` | 等待指定秒数,参数为浮点类型 |
| 等待(毫秒) | `WAIT(ms)`、`Sleep(ms)` | 等待指定毫秒数,参数为整数类型 |

示例:

```c
message1 >> arguments -@ csm
wait >> 1min 20s 500ms // 等待 1 分 20 秒 500 毫秒

message1 >> arguments -@ csm
wait(ms) >> 100 // 等待 100 毫秒

message1 >> arguments -@ csm
wait(s) >> 1.5 // 等待 1.5 秒
```

### 锚点与跳转

脚本中可定义命名锚点,并通过错误跳转或显式 `GOTO` 跳转到指定锚点继续执行。

- **锚点定义**:`<anchor_name>`,例如 `<setup>`、`<main>`、`<error_handler>`、`<cleanup>`,大小写不敏感。
- **条件跳转**:`?? goto >> <anchor_name>`,在前一条指令出错时跳转到指定锚点。省略条件表达式等同于"任意错误时跳转"。

`AUTO_ERROR_HANDLE_ANCHOR` 指令设置默认的错误跳转锚点(默认为 `<cleanup>`)。
`AUTO_ERROR_HANDLE_ENABLE` 指令开启自动错误处理,任何指令执行失败时,自动跳转到预设锚点。

示例:

```c
// 开启自动错误处理
AUTO_ERROR_HANDLE_ENABLE >> TRUE
// 将默认错误锚点改为 error_handler
AUTO_ERROR_HANDLE_ANCHOR >> error_handler

<setup> // ----- setup anchor ----

// 初始化失败不需要执行 stop,因此显式指定跳转到 cleanup
initialize >> daq1 -@ ai ?? goto >> <cleanup>

<main> // ----- main anchor ----

// 之后的所有指令,执行失败时将跳转到 error_handler
configure >> Onboard Clock;10,-10,RSE -@ ai
start -@ ai
acquire >> Channel:ch0;Num:1000 -@ ai

<error_handler> // ----- error handler anchor ----
stop -@ ai

<cleanup> // ----- cleanup anchor ----
close -@ ai
```

> [!NOTE]
> 自动错误处理**默认关闭**,需通过 `AUTO_ERROR_HANDLE_ENABLE >> TRUE` 显式开启。未开启时,指令执行出错后将继续执行下一条指令。

> [!NOTE]
> 锚点最常见的用途是划分脚本执行阶段,类似于 NI TestStand 序列中的 `<setup>`、`<main>`、`<cleanup>` 等阶段。

> [!NOTE]
> 锚点名称中的 `<>` 符号可省略,`GOTO >> cleanup` 与 `GOTO >> <cleanup>` 效果相同。
111 changes: 51 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,116 @@
# CSMStand-Lite
# CSMScript-Lite

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

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

此项目包括:
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.

1. **CSMStand-Lite Library**:一个轻量级的 CSM 脚本执行引擎,它本身也是基于 CSM 实现的模块。
- Engine:核心执行引擎,负责解析和执行 CSM 脚本,管理测试状态和结果。
- UI:用户界面,提供脚本管理、执行控制和结果查看功能。
- App:一个示例应用程序,展示如何使用 CSMStand 库进行脚本执行。
3. **实例工程**:展示如何使用 CSMStand-Lite 配合其他 CSM 模块,实现脚本执行和自动化测试。
This project includes:

![CSMStandApp](.github/csmstand%20ui.png)
- **CSMScript-Lite Library** — A lightweight CSM script execution engine, itself implemented as a CSM module.
- **Engine**: Core execution engine that parses and runs CSM scripts, managing test state and results.
- **UI**: User interface for script management, execution control, and result viewing.
- **App**: A sample application demonstrating how to use the CSMScript library.
- **Example Projects** — Demonstrate how to combine CSMScript-Lite with other CSM modules for script-driven automated testing.

## 依赖关系
![CSMScriptApp](.github/CSMScript%20UI.png)

- LabVIEW 2020 及以上版本
- NEVSTOP-LAB Palette
- Communicable State Machine (CSM) Framework
- Communicable State Machine(CSM)
## Dependencies

- LabVIEW 2020 or later
- [Communicable State Machine (CSM)](https://github.com/NEVSTOP-LAB/Communicable-State-Machine)
- CSM API String Arguments Support
- CSM MassData Parameter Support
- CSM INI Static Variable Support
- NEVSTOP-Programming-Palette
- NEVSTOP Programming Palette

## CSMStand-Lite Library 功能说明
## Features

### 基础功能:脚本执行
### Script Execution

支持 CSM 的全部命令,包括同步消息、异步消息、广播订阅等功能。详细的信息,请参考 CSM 框架的文档。
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.

### 返回值保存传递 (Return Value)
### Return Value Capture

通过 `=> 变量名` 语法,将指令的返回值保存到脚本的临时变量空间中,供后续指令使用。例如:
Use the `=> varName` syntax to save a command's return value into the script's temporary variable space for use in subsequent commands:

```c
message1 >> arguments -@ module1 => returnValueVar
message2 >> ${returnValueVar} -@ module2
```

> [!NOTE]
> CSM - Run Script.vi 中也支持此功能,此处的功能与之相同。

### 扩充指令 (Extended Commands)
> This feature is also supported in `CSM - Run Script.vi` and behaves identically.

CSMStand 内置了一些非 CSM 提供的扩充指令,用于实现基本功能,如跳转指令等。
### Extended Commands

格式与 CSM 指令类似:`指令 >> 参数`,指令名称大小写不敏感。
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.

| 指令集名称 | 指令 | 说明 |
| --------------------- | ------------------------ | ------------------------------------------------------------ |
| 跳转指令 | GOTO | 跳转到指定的 `<anchor>` |
| 开启/关闭自动错误处理 | AUTO_ERROR_HANDLE_ENABLE | 开启或关闭自动错误处理功能 |
| 设置自动错误跳转锚点 | AUTO_ERROR_HANDLE_ANCHOR | 设置自动错误跳转的锚点,默认为 `<cleanup>` |
| 等待指令1 | WAIT, Sleep | 等待指定的时间,支持 minute(min)、second(s)、microsecond(ms) |
| 等待指令2 | WAIT(s), Sleep(s) | 等待指定的时间,单位为秒,参数为 Float 类型 |
| 等待指令3 | WAIT(ms), Sleep(ms) | 等待指定的时间,单位为毫秒,参数为 NUMERIC 类型 |
| Category | Command | Description |
|---|---|---|
| Jump | `GOTO` | Jump to the specified `<anchor>` |
| Auto Error Handling | `AUTO_ERROR_HANDLE_ENABLE` | Enable or disable automatic error handling |
| Auto Error Anchor | `AUTO_ERROR_HANDLE_ANCHOR` | Set the error jump anchor (default: `<cleanup>`) |
| Wait | `WAIT`, `Sleep` | Wait for a specified duration; supports `min`, `s`, and `ms` units in one expression |
| Wait (seconds) | `WAIT(s)`, `Sleep(s)` | Wait for a float number of seconds |
| Wait (milliseconds) | `WAIT(ms)`, `Sleep(ms)` | Wait for an integer number of milliseconds |

举例:
Examples:

```c
message1 >> arguments -@ csm
wait >> 1min 20s 500ms // 等待 1 20 500 毫秒
wait >> 1min 20s 500ms // wait 1 minute, 20 seconds, and 500 milliseconds

message1 >> arguments -@ csm
wait(ms) >> 100 // 等待 100 毫秒
wait(ms) >> 100 // wait 100 milliseconds

message1 >> arguments -@ csm
wait(s) >> 1.5 // 等待 1.5
wait(s) >> 1.5 // wait 1.5 seconds
```

### 锚点跳转 (Anchor)

支持在脚本中定义锚点,并通过错误跳转或变量逻辑判断跳转到指定锚点继续执行脚本。
### Anchors and Jumps

- **锚点定义格式**:`<anchor_name>`,例如 `<setup>`、`<main>`、`<error_handler>`、`<cleanup>` 等,大小写不敏感。
- **锚点跳转格式**:`?? goto >> <anchor_name>` 语法,在指令执行错误时跳转到指定锚点继续执行脚本。缺省 expression 表示指令执行错误时跳转。
Scripts can define named anchors and jump to them on error or via explicit `GOTO` commands.

`AUTO_ERROR_HANDLE_ANCHOR` 指令可以设置自动错误跳转的锚点,缺省为 `<cleanup>`。
- **Anchor definition**: `<anchor_name>` — e.g., `<setup>`, `<main>`, `<error_handler>`, `<cleanup>`. Names are case-insensitive.
- **Conditional jump**: `?? goto >> <anchor_name>` — jumps to the anchor if the preceding command produced an error. Omitting the condition expression means "on any error."

`AUTO_ERROR_HANDLE_ENABLE` 指令可以开启自动错误处理功能,当指令执行错误时,自动跳转到预设的锚点继续执行脚本。
`AUTO_ERROR_HANDLE_ANCHOR` sets the default error-jump anchor (default: `<cleanup>`).
`AUTO_ERROR_HANDLE_ENABLE` turns on automatic error handling so that any failing command automatically jumps to the preset anchor.

例如:
Example:

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

<setup> // ----- setup anchor ----

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

<main> // ----- main anchor ----

// 之后的所有指令,如果执行失败,都将跳转到 error_handler 锚点
// All subsequent commands jump to error_handler on failure
configure >> Onboard Clock;10,-10,RSE -@ ai

start -@ ai

acquire >> Channel:ch0;Num:1000 -@ ai

<error_handler> // ----- error handler anchor ----
stop -@ ai

<cleanup> //----- cleanup anchor ----
<cleanup> // ----- cleanup anchor ----
close -@ ai

```

> [!NOTE]
> 默认的情况下,自动错误处理的是不打开的,需要通过 `AUTO_ERROR_HANDLE_ENABLE` 指令开启。
> 此时当发生错误时,将继续执行之后的指令。
> 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.

> [!NOTE]
> 最常见的锚点主要用于定义脚本运行阶段,例如可以定义类似 TestStand 序列的 `<setup>`, `<main>`, `<cleanup>` 等锚点。
> Anchors are most commonly used to define script phases, similar to the `<setup>`, `<main>`, and `<cleanup>` sequence stages in NI TestStand.

> [!NOTE]
> GOTO 指令和 AUTO_ERROR_HANDLE_ANCHOR 指令参数中可以携带 <> 符号,也可以不携带,例如 `GOTO >> cleanup` `GOTO >> <cleanup>` 效果相同。
> The `<>` brackets in anchor names are optional. `GOTO >> cleanup` and `GOTO >> <cleanup>` are equivalent.
Binary file modified _test/TEST-Main.vi
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/Engine/_Support/Internal Operation.vi
Binary file not shown.
Binary file added src/Engine/_Support/Populate Variables in CMD.vi
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/UI/Support/Sequence-DefaultStyle.vi
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/UI/VersionDialog(CSM).vi
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Loading