I am trying to read the CAN data from socketcan in my linux pc. I could not read any frame data, below is my mainwindow.cpp. Any suggestions ???
Solved
General and Desktop
-
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCanBus>
#include <QCanBusFrame>
#include <QtDebug>
#include<iostream>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
if (QCanBus::instance()->plugins().contains(QStringLiteral("socketcan")))
{
qDebug()<<"Avaliable";
}
QCanBusDevice *device = QCanBus::instance()->createDevice(
QStringLiteral("socketcan"), QStringLiteral("can0"));
device->connectDevice();
qDebug()<<"sucess";
while(device->framesAvailable())
{
const QCanBusFrame frame = device->readFrame();
QString test = frame.toString();
std::string text = test.toUtf8().constData();
qDebug()<<test;
std::cout<<text<<std::endl;
}
}MainWindow::~MainWindow()
{
delete ui;
}