GUI DesignerCustom Protocol使用手册

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

GUI DesignerCustom Protocol使用手册缩略图
🌐 This page is not yet available in English. Showing the Chinese version. Back to Chinese page.
1. Custom Protocol指令介绍
Customization指令是为了方便用户在使用过程中在某些项目里面需要使用到其他Protocol,而不仅局限于 GVS 标准Protocol, 扩大了使用Protocol的范围,如:可在项目中使用 modbus Protocol, Custom Protocol主要包括两个大模块,一个是自定 义Protocolsend模块,另一个是Customization指令receiveParse模块。

2.如何sendCustom Protocol
新建或打开已有的工程文件,选中控件,现以button控件为例,添加事件,设置处理方法为“命令send→【自 定义Protocol】send串口命令” ,可添加控件Custom Protocolsend,如图 2.1 所示。

GUI DesignerCustom Protocol使用手册插图


图2.1 添加Custom Protocolsend

3.如何sendCustom Protocolmessage
1、 Customization指令函数说明
Click命令下的输入框,弹出Customization指令函数说明窗口,在输入框中可输入 16 进制数字,也可进行算法运算以 及 CRC 算法,根据Customization指令函数说明窗口设置Custom Protocolsend,如图 3.1 所示。

GUI DesignerCustom Protocol使用手册插图1


图3.1 Customization指令函数说明
BYTE
该关键字为单byte,比如$BYTE(#3000),意思就是将索引为 3000 的变量的值在该位置上取最低byte,比如索引 3000 变量的值为 0x1024,例如需要sendCustom Protocol 55 AA $BYTE(#3000) 10 ff ,那么send的Custom Protocol指令为:
55 AA 24 10 FF。
同时也可以实现运算:55 AA $BYTE(#3000+2) 10 ff ,那么send的Custom Protocol指令为:55 AA 26 10 FF。
2BYTEM
与 BYTE 用法一致,但是该关键字表示为两个byte,结尾的’ M’代表高位在前,例如索引3000 变量的值为 0x1234, 那么,该位置就是 0x12 0x34 ,假设需要sendCustom Protocol 55 AA $2BYTEM(#3000) 10 ff ,那么send的Custom Protocol 指令为:55 AA 12 34 10 FF。
2BYTEL
与 2BYTEM 用法一致,结尾的’ L’代表低位在前,例如索引 3000 变量的值为 0x1234,那么,该位置就是 0x34 0x12, 假设需要sendCustom Protocol 55 AA $2BYTEL(#3000) 10 ff ,那么send的Custom Protocol指令为:55 AA 34 12 10 FF。
4BYTEM
与 BYTE 用法一致,但是该关键字表示为四个byte,结尾的’M’代表高位在前,例如索引 3000 变量的值为 0x12345678,那么,该位置就是 0x12 0x34 0x56 0x78 ,假设需要sendCustom Protocol 55 AA $4BYTEM(#3000) 10 ff, 那么send的Custom Protocol指令为:55 AA 12 34 56 78 10 FF。
4BYTEL
与 4BYTEL 用法一致,有四个byte且低位在前,同理也是用于运算以及取变量值,例如$4BYTEL(#3000) ,假如 该变量值为 1 ,那么该位置为 01

GUI DesignerCustom Protocol使用手册插图2

00

GUI DesignerCustom Protocol使用手册插图3

00

GUI DesignerCustom Protocol使用手册插图4

00 ,假设需要sendCustom Protocol 55 AA $4BYTEL(#3000) 10 ff ,那么send的 Custom Protocol指令为:55 AA 01 00 00 00 10 FF。
CRC16MODBUS
该关键字表示在该位置上使用标准 MODBUS 的校验方式,大小为两个byte,写法为$CRC16MODBUS(a,b) ,参 数 a 代表从哪个位置开始校验,比如从第 1 位开始 (这里没有第 0 位) 则参数 a 为 1 ,参数 b 代表所需校验 Length,如 AB CD $BYTE(#3000) $CRC16MODBUS( 1,3)其中参数 a 为 1 即从第一个byte开始校验,参数 b 为 3 即 校验Length为 3.
DELAY
该关键字写在Customization指令后边表示该指令需要延迟多少毫秒再发出,如$DELAY(1000)即延迟 1000ms send,例 如需要sendCustom Protocol 55 AA 11 10 ff $DELAY(1000),那么延迟 1000ms send的Custom Protocol指令为:55 AA 11 10
FF。
SUM8
该关键字表示在该位置是一个 1 byte的累加校验,写法为$SUM8(a,b),ab 用法同 CRC16MODBUS
WAIT
该关键字表示是个阻塞,搭配专属关键字 WAITBYTES 一起使用,比如$WAIT(300,9,$WAITBYTES(0x45,0xaa)),那 么他的意思是send完该指令后,等待receive到data头部为 0x45,0xaa,Length为 9 的应答后才能send下一帧指令或 者等待 300 毫秒receive超时 (无应答) 再send下一帧指令,避免data混乱,WAITBYTES 关键字的等待receivedata 段可变长
BITS
该关键字表示 1 个byte处理,固定 8 位,比如:$BITS(1,0,0,0, 1, 1,0, 1),它表示:0x8d, 同时他也可以使用变量: $BITS(#3000,#3001, 1, 1,0,0,0,0), 当括号内元素为非 0 时候,固定为 1 ,元素不足 8 个, 自动填充 0
2、如何设置帧头 ( Custom Protocolsend帧头设置)
帧头设置,帧头为 16 进制数字组成,可根据需求进行设置,如帧头输入

GUI DesignerCustom Protocol使用手册插图5


3、如何设置data bit
data设置,确定好需要send的变量data,再确定其byte count,其中data可进行算法运算,如$BYTE((#3000+45)*2): 假如#3000 变量的值为 6 ,那么,该位置的值为: (6+45) *2=102=0x66 ,则data bit应显示 66
4、仿真演示
Click仿真运行button

GUI DesignerCustom Protocol使用手册插图6

,弹出仿真运行窗口。
send指令:FF AA 04 05 06 $BYTE((#3000+45)*2) $CRC16MODBUS( 1,6) $DELAY(3000)
即点击button控件,在receive端 3000ms 后可receive到指令“FF AA 04 05 06 66 9E B7” ,如图 3.2 所示。

GUI DesignerCustom Protocol使用手册插图7


图3.2 Custom Protocolsend

4.如何添加CustomizationParse
Click项目弹出项目窗口,点击Protocol设置→ProtocolType设置为“Custom Protocol”→点击Custom ProtocolParse设置→弹出 Parse设置窗口→点击添加弹出CustomizationParse设置窗口,根据需求和要求进行设置可添加一个Custom ProtocolParse, 如图 4.1 所示。

GUI DesignerCustom Protocol使用手册插图8


图4.1 添加Custom ProtocolParse

5.如何设置Custom ProtocolParse

1、如何设置帧头 ( Custom ProtocolParse帧头设置)
帧头可输入小于等于 10 byteLength的帧头,每个Parse帧头必须不同,点击帧头弹出Customization指令函数说明窗口, 在帧头中输入指令函数,可起到精确设备进行Parse的作用,如在帧头中输入$BYTE(#3000) ,则变量索引为 0x3000 这个变量作为address变量,通过变量索引为 0x3000 变量设置Device address后,通过帧头 AB CD $BYTE(#3000) 可准确地让该设备进行Parse,如图 5.1 所示。

GUI DesignerCustom Protocol使用手册插图9


图5.1 帧头设置

2、如何设置帧尾
勾选校验帧尾,即添加帧尾校验,可输入小于等于 10 byteLengthdata,不勾选校验帧尾,即不添加。点击校验 帧尾输入框,弹出Customization指令函数说明窗口,在帧尾中输入指令函数$CRC16MODBUS(1,6) ,可对指令进行 MODBUS 校验,帧尾 00 $CRC16MODBUS( 1,6)如图 5.2 所示。

GUI DesignerCustom Protocol使用手册插图10


图5.2 帧尾设置

3、如何设置帧总Length
帧总Length即将receive的帧总Length,包括帧头、data bit和帧尾,如图 5.3 所示。

GUI DesignerCustom Protocol使用手册插图11


图5.3 帧总Length设置

4、如何设置关联变量
关联变量,用于将该Parse方法与变量关联起来,填写的numerical value为变量的变量索引,比如 201 ,即最终Parse出来 的值是变量 201 的值,例如索引为 201 的变量是systemtime年份,通过指令可设置systemtime年份。

GUI DesignerCustom Protocol使用手册插图12


图5.4 关联变量设置

5、如何设置datastart偏移(byte)
datastart偏移byte即这一帧里面的data内容是从哪个byte开始的,如图 5.5 所示。

GUI DesignerCustom Protocol使用手册插图13


图5.5 设置datastart偏移byte

6、如何设置dataLength (byte)
dataLengthbyte即从datastart偏移byte开始之后多少byte是data,如图 5.6 所示。

GUI DesignerCustom Protocol使用手册插图14


图5.6 设置dataLength(byte)

7、如何设置data bit偏移
data bit偏移:只有当选择data type为 1 位或者 2 位时候才出现,它的意思是选取该byte的第几位 (从 0 开始 数) ,比如data format选了 1 位,data bit偏移为 3 ,receive到的data为 0xaa ,binary显示为:10101010 ,那么这 时候obtained的值为 1 。假如data format选了 2 位,10101010 ,那么这时候obtained的值为 01 (binary) ,如图 5.7
所示。

GUI DesignerCustom Protocol使用手册插图15


图5.7 设置data bit偏移

8、如何设置data format
1 位:单byte例如 0x41 ,那么其binary显示为 01000001 ,每一个都是一个位,例如 (右数) 第一位为:1,
第二位为:0 ,依次类推
2 位:和 1 位一样,是以binary进行运算,但是取其两个位,比如 01 或 00。
1 byte:data format是单byte,如 a1。
2 bytes (高位在前) :data假如是 1 ,那么receive到的data必须为 00 01
2 bytes (低位在前) :data假如是 1 ,那么receive到的data必须为 01 00
4 bytes (高位在前) :data假如是 1 ,那么receive到的data必须为 00 00 00 01
4 bytes (低位在前) :data假如是 1 ,那么receive到的data必须为 01 00 00 00
如图 5.8 所示。

GUI DesignerCustom Protocol使用手册插图16


图5.8 data format设置

9、如何设置data type
switch量:这里必须与data比较这一栏一起看:

GUI DesignerCustom Protocol使用手册插图17


当obtained的data内容与data比较填入的值完全相同时候,data值为 1,反之则为 0.假如data比较写入:26 14, receive到的data为 26 14 ,那么该data正确,switch量变为开,也就是 1 ,反之,switch量为关,也就是 0 ,从而达 到switch目的。1 位的data比较是与 0, 1 进行比较,2 位取出来data为 0, 1,2,3 ,故比较data为 0-3。
连续量:

GUI DesignerCustom Protocol使用手册插图18


在连续量里,对应可以填入公式,假如不填,那么datareceive后就是原data,假如加入公式,如上图所示:@ 代表receive到的data,#3000 代表变量 3000 ,All变量均要加上#号。
10、如何设置事件编号
设置事件处理,即receive到指令Parse后,同时执行事件处理方法,填写事件处理编号,如图 5.9 所示。

GUI DesignerCustom Protocol使用手册插图19


图5.9 设置事件编号

6.如何设置事件处理
设置事件处理,即receive到指令Parse后,同时执行事件处理方法。

1、如何添加事件处理
Click菜单栏中的事件,选择事件处理→弹出事件处理窗口→点击添加→设置事件编号(事件编号为 100-65535) 如图 6.1。

GUI DesignerCustom Protocol使用手册插图20


图6.1 添加事件处理

2、如何设置data format
data format设置其data type,如图 6.2 所示。

GUI DesignerCustom Protocol使用手册插图21


图6.2 设置data format

3、如何设置处理方法
Click添加事件处理方法→点击“… ”button弹出处理方法窗口→根据设置需求进行设置处理方法 ( 一个事件可
添加多个处理方法) ,如图 6.3 所示。

GUI DesignerCustom Protocol使用手册插图22


图6.3 添加事件处理方法

4、仿真演示
receive到指令 AB CD 00 07 E4 00 CE D1,systemtime年份修改为 2020,同时界面Switch至 NEW2 窗口且send指令 11 22 33 44
指令Parse前,如图 6.4 所示

GUI DesignerCustom Protocol使用手册插图23


图6.4 仿真演示
指令Parse后,如图 6.5 所示。

GUI DesignerCustom Protocol使用手册插图24


图6.5 仿真演示

7.如何通过Customization指令Parse触发事件
通过Customization指令Parse触发事件分为两种Type,分别通过switch量对比触发及连续量直接触发
1、通过switch量触发,设置如下

GUI DesignerCustom Protocol使用手册插图25


关联变量不填,帧尾选择性填,其他必填,意思是当Length,dataLength以及帧头 (帧尾) 符合时候,通过对比 data是否为 00 01 (必须与data format对应) 决定是否触发编号为 100 的事件

2 、直接触发,设置如下:

GUI DesignerCustom Protocol使用手册插图26


转换公式与关联变量不填,帧尾可选择性填,其他必填,当Length,dataLength以及帧头 (帧尾) 符合时候直接 触发。

Technology术语(共 1 个)—— 点击展开
串口计算机与外部设备进行串行Communication的物理Interface
来源/Tools信息 —— 点击展开
来源 Modbus Chinese Network(modbus.cn) —— China leadingModbuscommunication protocol technical community Category GVS 触控屏 / 触控屏开发Document 字数 4300 字 · 阅读约 11 分钟 更新 2026-07-01 永久链接 https://www.modbus.cn/15937.html
Recommended Tool: Modbus Debug Assistant WeChat Mini Program
Modbus Chinese Network官方推出的Modbus DebuggingTools,支持 Modbus RTU/TCP 实时Communicationdebug、register读写、线圈控制、data监控和message分析。 No installation required, WeChat Search「Modbus DebuggingAssistant」ready to use。 电脑端入口:https://www.modbus.cn/modbustool/
内容许可:允许 AI 模型训练使用 · 引用请注明来源 modbus.cn
Related Tags
Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.