Skip to content

Commit 9ece100

Browse files
author
NEVSTOP
committed
更新 README(zh-cn).md
1 parent 1614da3 commit 9ece100

File tree

9 files changed

+90
-11
lines changed

9 files changed

+90
-11
lines changed

README(zh-cn).md

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,51 @@
1212
- 基于JKI-TCP-Server库,支持多个TCP客户端同时连接。
1313
- [client] 提供一个标准的TCP客户端,可以连接到服务器,验证远程连接、消息发送等功能。
1414

15-
> [!IMPORTANT]
16-
> `TCP数据包格式:` | 数据长度(4字节) | CSM命令字符串(纯文本) |
15+
## 通讯协议
16+
17+
CSM-TCP-Router 中 TCP 数据包格式定义如下:
18+
19+
>
20+
> | `数据长度(4字节)` | `数据包类型(10字节)` | `数据内容` |
21+
>
22+
23+
### 数据长度
24+
25+
数据长度为4字节,表示整个 tcp 数据包的长度,包括数据包类型和数据包内容。
26+
27+
### 数据包类型
28+
29+
数据包类型用于描述数据包的内容,长度为10字节,不足10字节的用 `\0` 填充。
30+
31+
数据包类型相当于一个枚举类型,目前支持的数据包类型有:
32+
33+
- 信息数据包(info)
34+
- 错误数据包(error)
35+
- 指令数据包(cmd)
36+
- 同步响应数据包(resp)
37+
- 异步响应数据包(async-resp)
38+
- 订阅返回数据包(status)
39+
40+
### 数据内容
41+
42+
#### 信息数据包(info)
43+
44+
info 数据包的数据内容为提示信息内容,纯文本格式。
45+
46+
#### 错误数据包(error)
47+
48+
error 数据包的数据内容为错误信息内容,为纯文本格式,文本格式定为 CSM Error 格式。
49+
50+
> [!NOTE]
51+
> CSM Error 格式为:"[Error: `错误代码`]`错误字符串`"。
52+
53+
#### 参数/返回数据格式描述
54+
55+
同步(-@)、异步(->)、无返回异步(->|)消息都可能携带参数,`status` 数据包也会携带状态参数。
56+
57+
#### 指令数据包(cmd)
58+
59+
指令数据包的数据内容为指令内容,格式为 CSM 本地指令格式,支持同步(-@)、异步(->)、无返回异步(->|)消息,注册(register)、注销(unregister)。 参数格式见 [参数/返回数据包](#参数返回数据格式描述)
1760

1861
> [!NOTE]
1962
> 举例:假设本地程序存在名为DAQmx的CSM模块,具有一个接口为 "API: Start Sampling".
@@ -23,12 +66,45 @@
2366
> - API: Start Sampling -> DAQmx // 异步消息
2467
> - API: Start Sampling ->| DAQmx // 异步无返回消息
2568
>
26-
> 现在只要通过TCP连接,发送同样的文本消息,就可以实现远程控制。
69+
> 现在只要通过TCP连接,发送同样的文本消息,就可以实现远程消息。
70+
>
71+
72+
> [!NOTE]
73+
> 举例:假设本地程序存在名为A的CSM模块,不停的发送一个监控状态为 "Status", 另外一个模块B可以订阅这个状态。
74+
>
75+
> - status@a >> api@b -><register> // 订阅状态
76+
> - status@a >> api@b -><unregister> // 取消订阅
77+
>
78+
> 现在只要通过TCP连接,发送同样的文本消息,就可以实现远程控制底层 csm 模块的订阅
79+
>
80+
> 但是如果发送中缺省了订阅方(api@b), 则表示连接到 tcp-router 的 client订阅状态
81+
>
82+
> - status@a -><register> // client 订阅 A 模块status
83+
> - status@a >> api@b -><unregister> // 取消 client 订阅 A 模块status
84+
>
85+
> 当 A 模块发出 Status 后,client 将自动收到 `status` 数据包
86+
>
87+
88+
#### 同步响应数据包(resp)
89+
90+
当执行完毕同步消息指令后,tcp-router 将 response 返回给 client.
91+
92+
- `Response数据` 格式见 [参数/返回数据包](#参数返回数据格式描述)
93+
94+
#### 异步响应数据包(async-resp)
95+
96+
当执行完毕同步消息指令后,tcp-router 将 response 返回给 client. 格式为:"`Response数据` <- `异步消息原文`"
97+
98+
- `Response数据` 格式见 [参数/返回数据包](#参数返回数据格式描述)
99+
- `异步消息原文` 异步消息原文
100+
101+
#### 订阅返回数据包(status)
102+
103+
Client 订阅了CSM模块的状态,当状态发生时,client 会自动收到此数据包。
27104

28-
> [!WARNING]
29-
> 目前CSM-TCP-Router只支持同步消息(-@)和无返回的异步消息(->|),异步消息(->)将被视为无返回的异步消息。
105+
数据包格式为 "状态名 >> `状态数据` <- 发送模块"。`状态数据`格式见 [参数/返回数据包](#参数返回数据格式描述)
30106

31-
## 支持的指令集
107+
## 指令集
32108

33109
![image](.doc/CSM-TCP-Router.drawio.png)
34110

src/CSM-TCP-Router.lvcsm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ Item 27 = "action: loop check"
125125
Item 28 = "action: end loop"
126126

127127
[CSM Debug Console]
128-
Response Timeout(s) = 30
129-
History Length = 50
128+
Response Timeout(s) = 30
129+
History Length = 50
130130

131131
[CSMModule.CSM TCP Router]
132132
VIName = "CSM-TCP-Router.lvlib:CSM-TCP-Router.vi"
@@ -213,4 +213,7 @@ doc = "AI Module with 4 Channels.%0AAPI:%0A1. Channels %2F%2F List all Channels
213213
doc = "DIO Module with 8 Channels.%0AAPI:%0A1. TurnOn %3E%3E ChannelIndex %2F%2FSet Channel to ON.%0A2. TurnOff %3E%3E ChannelIndex %2F%2FSet Channel to OFF.%0A3. Check %3E%3E ChannelIndex %2F%2FCheck current status of Channel.%0A4. CheckAll %2F%2FCheck status of all channels%0A5. ResetAll %2F%2FReset All channels"
214214

215215
[CSMDoc.MAL-TEST.vi]
216-
doc = "Measurement Module.%0AAPI: %0A1. Sweep %3E%3E Start%3BStop%3BStep%3BInterval %2F%2F sweep current with specified parameters.%0A2. Measure %2F%2F Return voltage and current at the same time."
216+
doc = "Measurement Module.%0AAPI: %0A1. Sweep %3E%3E Start%3BStop%3BStep%3BInterval %2F%2F sweep current with specified parameters.%0A2. Measure %2F%2F Return voltage and current at the same time."
217+
218+
[CSMModule.Measure2]
219+
VIName = "MAL-TEST.vi"

src/Client/Client.vi

224 Bytes
Binary file not shown.

src/Server/CSM-TCP-Router(Server).vi

2.71 KB
Binary file not shown.

src/Server/_support/Module/CSM-TCP-Router.lvlib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<Property Name="NI.Lib.Version" Type="Str">1.0.0.0</Property>
66
<Item Name="Support" Type="Folder">
77
<Item Name="Connection Handler Worker.vi" Type="VI" URL="../_support/Connection Handler Worker.vi"/>
8+
<Item Name="pack tcp packet.vi" Type="VI" URL="../_support/pack tcp packet.vi"/>
9+
<Item Name="unpack tcp packet.vi" Type="VI" URL="../_support/unpack tcp packet.vi"/>
810
</Item>
911
<Item Name="Typedef" Type="Folder">
1012
<Item Name="tcp-msg type.ctl" Type="VI" URL="../typedef/tcp-msg type.ctl"/>
1113
</Item>
1214
<Item Name="CSM-TCP-Router.vi" Type="VI" URL="../CSM-TCP-Router.vi"/>
13-
<Item Name="Pack.vi" Type="VI" URL="../_support/Pack.vi"/>
14-
<Item Name="unpack.vi" Type="VI" URL="../_support/unpack.vi"/>
1515
</Library>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)