惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
量子位
Martin Fowler
Martin Fowler
月光博客
月光博客
P
Proofpoint News Feed
博客园_首页
Y
Y Combinator Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
H
Help Net Security
U
Unit 42
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 夕西行

miniconda安装(windows)到D盘(环境也在D盘) 显卡、cuda、pytorch版本确定与安装 conda的安装与使用 conda虚拟环境中的pip、No module named问题、missing the 'build_editable' hook和PEP660 mmyolo与官方yolo,在背景数据集上的注意事项 跨平台的文件夹映射cifs WinSCP复制时报 Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 0 CMakeLists.txt之include、lib labelImg安装、改软件后打包成exe、改软件功能 Jetson插网线后启动慢 mmyolo数据集、训练 mmyolo安装 QString有中文空格时 VS2015下载 Qt5.15.2在线安装 编译Arm Qt5.14.2(在Arm上本地编译) Qt5.14.2下载 VS2022编译运行VS2015的项目 二进制字面量、字节序、串口发送、转16进制时符号扩展问题 QString的toStdString().c_str()坑
向串口发送数据的方式
夕西行 · 2025-04-12 · via 博客园 - 夕西行

1、远程发送,使用libssh

如Windows通过ssh向Arm板发送指令,Arm板依据指令向自己的串口ttyTHS1发送数据。

2、本地发送,使用QSerialPort 

如Arm板向自己的串口ttyTHS1发送数据。

以向 /dev/ttyTHS1 串口发送 0xAA为例,DeepSeek示例代码如下

#include <QSerialPort>
#include <QDebug>

void sendHexViaSerial(const QString& portName, uint8_t byte) {
    QSerialPort serial;
    serial.setPortName(portName);  // "/dev/ttyTHS1"
    serial.setBaudRate(QSerialPort::Baud115200);  // 根据设备调整
    serial.setDataBits(QSerialPort::Data8);
    serial.setParity(QSerialPort::NoParity);
    serial.setStopBits(QSerialPort::OneStop);

    if (!serial.open(QIODevice::WriteOnly)) {
        qDebug() << "Failed to open serial port:" << serial.errorString();
        return;
    }

    char data = static_cast<char>(byte);  // 0xAA
    if (serial.write(&data, 1) == -1) {
        qDebug() << "Failed to write data:" << serial.errorString();
    } else {
        qDebug() << "Sent:" << QByteArray(1, data).toHex();
    }

    serial.close();
}

int main() {
    sendHexViaSerial("/dev/ttyTHS1", 0xAA);
    return 0;
}