短故事:我有TI AM335x armv7l处理器开发板,它运行嵌入式Linux3.2.0。我想从CAN总线中读取数据并将其可视化。我不知道该怎么开始。
更长的故事:所以我有一个TI AM335x开发板从GOEMBED (http://goembed.com/index.php/Products/detail/tpid/25仿真器到beaglebone黑色)。它使用运行Linux3.2.0的armv7l处理器。
我把一个CAN模块连接到开发板上。这个CAN模块每秒钟向CAN总线发送相同的CAN消息.
通过在终端中输入以下命令,我可以可视化can消息。
ip link set can0 type can bitrate 500000 triple-sampling on
ip link set can0 up
candump can0
此时,我可以看到can消息的ID和数据。
root@goembed:~# ip link set can0 type can bitrate 500000 triple-sampling on
root@goembed:~# ip link set can0 up
root@goembed:~# candump can0
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
can0 1FC0000F [8] F5 F8 F1 00 00 00 F2 F3
现在最大的问题是,如何将这些数据输入qt应用程序?我想将消息的数据打印到文本框中。
希望有人能给我一些关于如何从这个开始的提示,这样我就可以从中学到什么?
亲切的问候
发布于 2017-05-24 11:22:52
我找到了一个简单的解决办法。因此,由于我想读取我的嵌入式系统中的所有消息,我很容易就可以接收到我的QProcess的响应。
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&proc3,SIGNAL(readyRead()),this, SLOT(dataReady()));
QD << QDir::currentPath();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::dataReady()
{
while(proc3.bytesAvailable()){
QString in = proc3.readLine();
QString out;
QRegExp reg(" can([01]) ([0-9A-F]+) \\[([0-9]+)\\] ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+) ([0-9A-F]+)");
if(reg.indexIn(in)>=0){
out = "from Can%1 Id:%2 amount bytes:%3 first byte:%4 second byte:%5 third byte:%6 fourth byte:%7 fifth byte:%8 sixth byte:%9 seventh byte:%10 eight byte:%11";
out = out.arg(reg.cap(1)).arg(reg.cap(2)).arg(reg.cap(3)).arg(reg.cap(4)).arg(reg.cap(5)).arg(reg.cap(6)).arg(reg.cap(7)).arg(reg.cap(8)).arg(reg.cap(9)).arg(reg.cap(10)).arg(reg.cap(11));
}else{
out = "Error:" + in;
}
ui->plainTextEdit->appendPlainText(out);
}
}
void MainWindow::on_startButton_clicked()
{
QString cmd1 = "ip";
QStringList opt1;
QD;
opt1 << "link"<< "set"<< "can0"<< "bitrate"<< "500000"<< "triple-sampling"<< "on";
proc1.start(cmd1,opt1);
QString cmd2 = "ip";
QStringList opt2;
QD;
opt2 << "link"<< "set"<< "can0"<< "up";
proc2.start(cmd2,opt2);
QString cmd3 = "candump";
QStringList opt3;
QD;
opt3 << "can0";
proc3.start(cmd3,opt3);
}
void MainWindow::on_stopButton_clicked()
{
QString cmd4 = "ip";
QStringList opt4;
QD;
opt4 << "link"<< "set"<< "can0"<< "down";
proc4.start(cmd4,opt4);
}
因此,在这一点上,我可以将ID、数据库数量和数据库本身放入变量中。所以游戏时间可以开始了!我希望这对其他人有帮助。如果人们知道进步,就让我知道。亲切的问候
发布于 2017-05-22 19:58:19
理想情况下,您应该为您的平台构建QT5.8并使用QtSerialBus模块。否则,您将面临将QtSerialBus移植到Qt 4的乏味任务,这并不特别困难。
一旦您访问了串行总线模块,您就可以很容易地得到实时通知,因为数据包可以到达,然后以任何方式显示它们。例如,您可以在模型中积累它们,并在QTableView
中显示它们。
https://stackoverflow.com/questions/44119753
复制相似问题