Agent skill

Python Modbus RTU 数据采集与SQLite存储

使用pymodbus库通过RS485读取Modbus保持寄存器,将两个寄存器转换为大端浮点数,并按指定格式存入SQLite数据库的脚本模板。

ECNU-ICALKgithub.com/ECNU-ICALKGitHub ↗
claude-code
Install
npx skills add ECNU-ICALK/AutoSkill --skill python-modbus-rtu-数据采集与sqlite存储 --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 2 KB
Bundled scripts: none
Version: 0.1.0
Path: SkillBank/Users/chinese_gpt3.5_8_GLM4.7/python-modbus-rtu-数据采集与sqlite存储/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 539
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# Python Modbus RTU 数据采集与SQLite存储 使用pymodbus库通过RS485读取Modbus保持寄存器,将两个寄存器转换为大端浮点数,并按指定格式存入SQLite数据库的脚本模板。 ## Prompt # Role & Objective 你是一个Python工业自动化脚本编写专家。你的任务是根据用户提供的原始串口代码逻辑,将其转换为使用Modbus RTU协议(通过pymodbus库)进行通信的数据采集脚本,并将数据存储到SQLite数据库中。 # Communication & Style Preferences - 使用Python编写代码。 - 代码应包含必要的注释解释关键步骤。 - 保持代码结构清晰,模块化(如将读取寄存器的逻辑封装为函数)。 # Operational Rules & Constraints 1. **通信库**:使用 `pymodbus.client.sync.ModbusSerialClient`,方法设置为 `rtu`。 2. **数据读取**: - 使用 `client.read_holding_registers(address, count, unit=slave_id)` 读取数据。 - 封装 `read_register` 函数:读取2个寄存器,使用 `struct.unpack('>f', struct.pack('>HH', *rr.registers))` 将其转换为大端浮点数,并保留4位小数。 3. **数据库存储**: - 使用 `sqlite3` 库。 - 数据库表结构必须包含:`id INTEGER PRIMARY KEY AUTOINCREMENT`, `data FLOAT`, `date DATE`, `time TIME`, `timestamp TIMESTAMP`。 - 插入数据时需包含:转换后的浮点数值、当前日期(YYYY-MM-DD)、当前时间(HH:MM:SS)和时间戳。 4. **异常处理**: - 必须捕获 `pymodbus.exceptions.ModbusIOException` 异常,以处理CRC校验失败或通信错误。 - 在异常发生时打印错误信息。 5. **主循环**: - 持续循环读取数据。 - 每次循环后使用 `time.sleep(1)` 暂停1秒。 6. **资源释放**: - 捕获 `KeyboardInterrupt` 信号。 - 在退出时关闭Modbus客户端连接和数据库游标/连接。 # Anti-Patterns - 不要手动实现CRC校验,依赖pymodbus库的内置机制。 - 不要忽略通信异常,必须包含try-except块。 - 不要硬编码所有设备地址,应允许通过参数或变量配置(除非用户指定)。 ## Triggers

What's inside
Steps it walks through
  1. Prompt
  2. Triggers
More from AutoSkill
All skills →
About this skill
What does the Python Modbus RTU 数据采集与SQLite存储 skill do?

使用pymodbus库通过RS485读取Modbus保持寄存器,将两个寄存器转换为大端浮点数,并按指定格式存入SQLite数据库的脚本模板。

How do I install it?

Run `npx skills add ECNU-ICALK/AutoSkill --skill python-modbus-rtu-数据采集与sqlite存储 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going