summaryrefslogtreecommitdiffstats
path: root/examples/serialbus/can
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-02-02 18:48:55 +0100
committerIvan Solovev <ivan.solovev@qt.io>2023-02-10 12:03:53 +0100
commitbe1a4f7e32503a9de156a454ccd9c6e99f79e4a9 (patch)
tree37f391e7d638a721d2ab00906037c08386427514 /examples/serialbus/can
parenta18c97f1a897e4653a47a45976d78bea5a2243be (diff)
CAN Manager Example: extend documentation
Extend the documentation so that it actually highlights the main features shown by the example. Also update the documentation to match the guidelines: * update screenshot * add Connectivity category Task-number: QTBUG-110890 Pick-to: 6.5 Change-Id: I9c75488440be23885c7751f6d00018e9537cdfa2 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples/serialbus/can')
-rw-r--r--examples/serialbus/can/mainwindow.cpp8
-rw-r--r--examples/serialbus/can/sendframebox.cpp2
2 files changed, 10 insertions, 0 deletions
diff --git a/examples/serialbus/can/mainwindow.cpp b/examples/serialbus/can/mainwindow.cpp
index 1f89bcb..3234043 100644
--- a/examples/serialbus/can/mainwindow.cpp
+++ b/examples/serialbus/can/mainwindow.cpp
@@ -107,9 +107,11 @@ void MainWindow::connectDevice()
else
m_model->setQueueLimit(0);
+//! [create_can_device_0]
QString errorString;
m_canDevice.reset(QCanBus::instance()->createDevice(p.pluginName, p.deviceInterfaceName,
&errorString));
+//! [create_can_device_0]
if (!m_canDevice) {
m_status->setText(tr("Error creating device '%1', reason: '%2'")
.arg(p.pluginName, errorString));
@@ -118,12 +120,14 @@ void MainWindow::connectDevice()
m_numberFramesWritten = 0;
+//! [create_can_device_1]
connect(m_canDevice.get(), &QCanBusDevice::errorOccurred,
this, &MainWindow::processErrors);
connect(m_canDevice.get(), &QCanBusDevice::framesReceived,
this, &MainWindow::processReceivedFrames);
connect(m_canDevice.get(), &QCanBusDevice::framesWritten,
this, &MainWindow::processFramesWritten);
+//! [create_can_device_1]
if (p.useConfigurationEnabled) {
for (const ConnectDialog::ConfigurationItem &item : p.configurations)
@@ -244,6 +248,7 @@ void MainWindow::processReceivedFrames()
if (!m_canDevice)
return;
+//! [receive_can_frame]
while (m_canDevice->framesAvailable()) {
m_numberFramesReceived++;
const QCanBusFrame frame = m_canDevice->readFrame();
@@ -266,6 +271,7 @@ void MainWindow::processReceivedFrames()
m_model->appendFrame(QStringList({QString::number(m_numberFramesReceived),
time, flags, id, dlc, data}));
}
+//! [receive_can_frame]
}
void MainWindow::sendFrame(const QCanBusFrame &frame) const
@@ -273,7 +279,9 @@ void MainWindow::sendFrame(const QCanBusFrame &frame) const
if (!m_canDevice)
return;
+//! [send_can_frame]
m_canDevice->writeFrame(frame);
+//! [send_can_frame]
}
void MainWindow::onAppendFramesTimeout()
diff --git a/examples/serialbus/can/sendframebox.cpp b/examples/serialbus/can/sendframebox.cpp
index e26524e..4f6025f 100644
--- a/examples/serialbus/can/sendframebox.cpp
+++ b/examples/serialbus/can/sendframebox.cpp
@@ -208,6 +208,7 @@ SendFrameBox::SendFrameBox(QWidget *parent) :
frameIdOrPayloadChanged();
connect(m_ui->sendButton, &QPushButton::clicked, [this]() {
+ //! [prepare_can_frame]
const uint frameId = m_ui->frameIdEdit->text().toUInt(nullptr, 16);
QString data = m_ui->payloadEdit->text();
m_ui->payloadEdit->setText(formatHexData(data));
@@ -222,6 +223,7 @@ SendFrameBox::SendFrameBox(QWidget *parent) :
frame.setFrameType(QCanBusFrame::ErrorFrame);
else if (m_ui->remoteFrame->isChecked())
frame.setFrameType(QCanBusFrame::RemoteRequestFrame);
+ //! [prepare_can_frame]
emit sendFrame(frame);
});