Loading...
Loading...
698/645 electricity meter protocol serial port frame sending and parsing Skill, supporting frame assembly, sending, receiving, parsing and assertion verification, used for fast regression verification after bug fixing
npx skill4agent add ruiwarn/skills meter-protocol-serial698645DL/T698DL/T645OADDIserial frame sendingframe assemblyCOM portprotocol debuggingregression testframe sending verificationread meter datawrite meter parameters# 645读数据(只组帧)
python3 $SKILL_DIR/scripts/protocol_cli.py proto=645 op=read di=00010000
# 645读数据(串口发送)
python3 $SKILL_DIR/scripts/protocol_cli.py port=/dev/ttyUSB0 proto=645 op=read di=00010000
# 698读数据
python3 $SKILL_DIR/scripts/protocol_cli.py proto=698 op=read oad=40010200
# 698设置参数
python3 $SKILL_DIR/scripts/protocol_cli.py proto=698 op=set oad=43000300 value=bool:truepython.exe# WSL中访问Windows COM口(推荐方式:使用 Python 包装脚本)
python3 $SKILL_DIR/meter-cmd.py port=COM10 proto=645 op=read di=04000401
# 或者手动转换路径
SKILL_PATH=$(wslpath -w /home/xx/.agents/skills/meter-protocol-serial/scripts/protocol_cli.py)
python.exe "$SKILL_PATH" port=COM10 proto=645 op=read di=04000401# 错误方式1(WSL Python无法访问Windows串口)
python3 protocol_cli.py port=COM10 ... # 会报错: No such file or directory
# 错误方式2(Windows Python无法直接访问WSL路径)
python.exe /home/xx/.../protocol_cli.py # 会报错: can't open file| Windows | WSL Device |
|---|---|
| COM1 | /dev/ttyS1 |
| COM10 | /dev/ttyS10 |
# Windows直接运行(PowerShell)
python.exe C:\path\to\scripts\protocol_cli.py port=COM10 proto=645 op=read di=04000401
# Windows直接运行(CMD)
python C:\path\to\scripts\protocol_cli.py port=COM10 proto=645 op=read di=04000401# Linux/WSL通用(只组帧,无串口)
python3 $SKILL_DIR/scripts/protocol_cli.py proto=645 op=read di=00010000 expect=ack
# WSL+Windows串口(推荐直接走包装脚本)
python3 $SKILL_DIR/meter-cmd.py port=COM3 proto=645 op=read di=00010000 expect=ack| Protocol | Operation | Description |
|---|---|---|
| DL/T645-2007 | read | Read data |
| DL/T645-2007 | write | Write data |
| DL/T698.45 | read | GET.request.normal |
| DL/T698.45 | set | SET.request.normal |
| Parameter | Description | Example |
|---|---|---|
| proto | Protocol type | 645 or 698 |
| op | Operation type | read / write / set |
| port | Serial port (optional) | /dev/ttyUSB0 or COM3 |
| timeout_ms | Timeout duration | 2000 |
| baud | Baud rate | 2400 (default for 645), 9600 (default for 698) |
| data_bits | Data bits | 8 |
| parity | Parity bit | even / odd / none |
| stop_bits | Stop bit | 1 |
| expect | Assertion condition | ack / hex:0102 / bool:true / int:1 |
| decode_hint | Decoding hint | hex / ascii / uint16_le / uint32_le / bcd |
| note | Note | Any text |
| Parameter | Description | Example |
|---|---|---|
| di | Data identifier (8-bit hexadecimal) | 00010000 |
| addr | Meter address (12-bit BCD) | 000000000001 |
| value | Write data value | hex:010203 / ascii:abc |
| fe_count | Number of leading FE bytes | 4 |
| raw_prefix | Prefix data | hex:041234 |
| raw_suffix | Suffix data | hex:0000 |
| Parameter | Description | Example |
|---|---|---|
| oad | Object Attribute Descriptor (8-bit hexadecimal) | 40010200 |
| server_addr | Server address | 000000000000 |
| client_addr | Client address | 00 |
| ca | Client address (abbreviated) | 00 |
| value | Write data value | bool:true / int32:123 / string:abc |
hex:01020304ascii:abcbool:true|falseint8:1int16:1int32:1uint8:1uint16:1uint32:1enum:1octet:112233string:abchex:010203MODE=frame_only|serial_roundtrip
PROTO=645|698
OP=read|write|set
TARGET=di:xxx|oad:xxx
REQUEST_HEX=68 AA AA ... CS 16
RESPONSE_HEX=68 BB BB ... CS 16 (串口模式)
FRAME_CHECK=ok|fail|partial
DECODE_STATUS=ok|partial|fail
RESULT=success|error|timeout
DATA_HEX=01020304
DATA_TYPED=typed_value (如果有)
ASSERT_RESULT=pass|fail|skipped
ASSERT_REASON=... (如果有)
SUMMARY=简短中文总结645_ADDR=000000000001
645_CTRL=91
645_DI=00010000698_SERVER_ADDR=45AAAAAAAAAAAA (地址特征字节+6字节地址)
698_CLIENT_ADDR=00
698_CTRL=43 (控制域: DIR=0,PRM=1,分帧=0,扰码=0,功能码=3)
698_PIID=00
698_OAD=40010200
698_DAR=00 (数据访问结果,00=成功)| Code Value | Meaning |
|---|---|
| 0 | Success |
| 2 | Input parameter error |
| 3 | Serial port opening or sending failure |
| 4 | Timeout with no response |
| 5 | Response received but parsing failed |
| 6 | Assertion failed |
执行命令:
python3 $SKILL_DIR/scripts/protocol_cli.py proto=645 op=read di=00010000
输出:
MODE=frame_only
PROTO=645
OP=read
TARGET=di:00010000
REQUEST_HEX=FEFEFEFE6800000000000068110433333333AD16
...
SUMMARY=组帧成功: FEFEFEFE6800000000000068110433...执行命令:
python3 $SKILL_DIR/scripts/protocol_cli.py port=COM3 proto=645 op=read di=00010000 expect=ack
输出:
MODE=serial_roundtrip
PROTO=645
OP=read
...
ASSERT_RESULT=pass
SUMMARY=断言通过: 收到响应AAAAAAAAAAAAAAAAAAAAAAAA00scripts/
├── protocol_cli.py # CLI主入口
├── request_parser.py # 请求解析
├── profiles.py # 默认配置
├── serial_transport.py # 串口收发
├── proto_645.py # 645协议处理
├── proto_698.py # 698协议处理
├── value_codec.py # 值编解码
└── result_formatter.py # 结果格式化