单片机设计_串口调试工具

一、设计思路

  1. HTML结构完整 - 标签闭合正确

  2. CSS样式齐全 - 浅绿色主题,响应式布局

  3. JavaScript逻辑完整 - 串口连接、读写、错误处理齐全

🎯 功能清单

功能模块 说明
串口连接 支持选择设备,配置波特率/数据位/停止位/校验位/流控
数据接收 支持字符串/HEX显示,自动滚动
数据发送 支持字符串/HEX模式,可选换行符,Ctrl+Enter快捷键
界面主题 浅绿色护眼风格

二、界面展示

三、部分代码

html 复制代码
<body>
<div class="serial-panel">
    <div class="panel-header">
        <div class="title">
            <h1>🍃 串口调试</h1>
            <div class="badge">Web Serial API</div>
        </div>
        <div class="status-area">
            <div class="led" id="statusLed"></div>
            <div class="status-text" id="statusText">未连接</div>
        </div>
    </div>

    <div class="control-bar">
        <div class="param-group">
            <label>波特率</label>
            <select id="baudRate">
                <option value="9600">9600</option>
                <option value="19200">19200</option>
                <option value="38400">38400</option>
                <option value="57600">57600</option>
                <option value="115200" selected>115200</option>
                <option value="230400">230400</option>
                <option value="460800">460800</option>
            </select>
        </div>
        <div class="param-group">
            <label>数据位</label>
            <select id="dataBits">
                <option value="7">7</option>
                <option value="8" selected>8</option>
            </select>
        </div>
        <div class="param-group">
            <label>停止位</label>
            <select id="stopBits">
                <option value="1">1</option>
                <option value="2">2</option>
            </select>
        </div>
        <div class="param-group">
            <label>校验位</label>
            <select id="parity">
                <option value="none">None</option>
                <option value="even">Even</option>
                <option value="odd">Odd</option>
            </select>
        </div>
        <div class="param-group">
            <label>流控</label>
            <select id="flowControl">
                <option value="none">None</option>
                <option value="hardware">Hardware</option>
            </select>
        </div>
        <button id="connectBtn" class="primary">🔌 连接设备</button>
        <button id="disconnectBtn" class="danger">⛔ 断开</button>
    </div>

    <div class="main-area">
        <!-- 接收区域 -->
        <div class="log-panel">
            <div class="section-title">
                <span>📥 数据接收 (RX)</span>
                <button id="clearReceiveBtn" class="clear-btn">清空接收区</button>
            </div>
            <div class="receive-area">
                <div class="log-box" id="receiveLog">
                    [等待连接串口设备...]<br>
                </div>
            </div>
        </div>

        <!-- 发送区域 -->
        <div class="send-panel">
            <div class="section-title">
                <span>📤 数据发送 (TX)</span>
                <button id="clearSendInputBtn" class="clear-btn">清空编辑区</button>
            </div>
            <div class="input-area">
                <textarea id="sendData" placeholder="输入要发送的字符串或十六进制 (根据下方模式)"></textarea>
                <div class="send-options">
                    <div class="checkbox-label">
                        <input type="checkbox" id="hexSendMode"> <span>HEX 发送模式</span>
                    </div>
                    <div class="checkbox-label">
                        <input type="checkbox" id="appendNewline" checked> <span>发送换行符 \r\n</span>
                    </div>
                    <button id="sendBtn" style="flex:1;">✈️ 发送数据</button>
                </div>
                <div class="send-options" style="margin-top: 12px;">
                    <div class="checkbox-label">
                        <input type="checkbox" id="hexReceiveMode"> <span>HEX 显示模式</span>
                    </div>
                    <div class="checkbox-label">
                        <input type="checkbox" id="autoScroll" checked> <span>自动滚动</span>
                    </div>
                    <button id="clearReceiveBtn2" class="clear-btn">清空接收</button>
                </div>
            </div>
        </div>
    </div>
    <footer>
        💡 浅绿护眼主题 | 支持HEX/字符串收发 | 有问题联系-liming-
    </footer>
</div>
相关推荐
ClouGence8 小时前
Oracle 数据同步为什么会出现数据不一致?长事务是常被忽略的原因
数据库·后端·oracle
飞将10 小时前
从零实现数据库(2)——HashIndex + IndexManager
数据库
Nturmoils1 天前
订单列表慢查询,先看 WHERE、ORDER BY 和 LIMIT
数据库
渣波1 天前
拒绝 SQL 焦虑!手把手带你用 NestJS + Prisma + DTO 写出“防弹”级后端代码
javascript·数据库·后端
葫芦和十三2 天前
图解 MongoDB 08|ESR 原则:复合索引的字段顺序怎么定
后端·mongodb·agent
葫芦和十三2 天前
图解 MongoDB 07|索引类型:七种索引,七种访问形状
后端·mongodb·agent
FreakStudio2 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
倔强的石头_2 天前
KingbaseES 新版MySQL 兼容版体验:旧版迁移 + 功能实测
数据库
葫芦和十三2 天前
图解 MongoDB 06|模式演进:无 schema 是优势还是债
后端·mongodb·agent
葫芦和十三3 天前
图解 MongoDB 05|文档模型设计:内嵌 vs 引用,反范式不是免费午餐
后端·mongodb·agent