summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/serialbus/can/mainwindow.cpp29
-rw-r--r--examples/serialbus/can/mainwindow.h3
-rw-r--r--examples/serialbus/can/mainwindow.ui24
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp32
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.cpp49
-rw-r--r--src/serialbus/doc/src/peakcan.qdoc17
-rw-r--r--src/serialbus/doc/src/qtcanbus-backends.qdoc4
-rw-r--r--src/serialbus/doc/src/socketcan.qdoc16
-rw-r--r--src/serialbus/doc/src/tinycan.qdoc17
-rw-r--r--src/serialbus/qcanbusdevice.cpp18
-rw-r--r--src/tools/canbusutil/readtask.cpp19
11 files changed, 142 insertions, 86 deletions
diff --git a/examples/serialbus/can/mainwindow.cpp b/examples/serialbus/can/mainwindow.cpp
index a04a0f4..01101c9 100644
--- a/examples/serialbus/can/mainwindow.cpp
+++ b/examples/serialbus/can/mainwindow.cpp
@@ -44,6 +44,7 @@
#include <QCanBusFrame>
#include <QCanBus>
+#include <QCloseEvent>
#include <QTimer>
#include <QtCore/qbytearray.h>
@@ -143,8 +144,15 @@ void MainWindow::connectDevice()
m_ui->sendMessagesBox->setEnabled(true);
- showStatusMessage(tr("Backend: %1, Connected to: %2")
- .arg(p.backendName).arg(p.deviceInterfaceName));
+ QVariant bitRate = m_canDevice->configurationParameter(QCanBusDevice::BitRateKey);
+ if (bitRate.isValid()) {
+ showStatusMessage(tr("Backend: %1, connected to %2 at %3 kBit/s")
+ .arg(p.backendName).arg(p.deviceInterfaceName)
+ .arg(bitRate.toInt() / 1000));
+ } else {
+ showStatusMessage(tr("Backend: %1, connected to %2")
+ .arg(p.backendName).arg(p.deviceInterfaceName));
+ }
}
}
@@ -170,6 +178,12 @@ void MainWindow::framesWritten(qint64 count)
qDebug() << "Number of frames written:" << count;
}
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ m_connectDialog->close();
+ event->accept();
+}
+
static QByteArray dataToHex(const QByteArray &data)
{
QByteArray result = data.toHex().toUpper();
@@ -195,12 +209,15 @@ void MainWindow::checkMessages()
if (frame.frameType() == QCanBusFrame::ErrorFrame) {
interpretError(view, frame);
} else {
- view += QLatin1String("Id: ");
- view += QString::number(id, 16).toUpper();
+ const char *format =
+ frame.hasExtendedFrameFormat() ? "Id: %08X" : "Id: %03X";
+ view += QString::asprintf(format, static_cast<uint>(id));
view += QLatin1String(" bytes: ");
view += QString::number(dataLength, 10);
- view += QLatin1String(" data: ");
- view += dataToHex(frame.payload());
+ if (frame.frameType() != QCanBusFrame::RemoteRequestFrame) {
+ view += QLatin1String(" data: ");
+ view += dataToHex(frame.payload());
+ }
}
if (frame.frameType() == QCanBusFrame::RemoteRequestFrame) {
diff --git a/examples/serialbus/can/mainwindow.h b/examples/serialbus/can/mainwindow.h
index aff6c94..de4d442 100644
--- a/examples/serialbus/can/mainwindow.h
+++ b/examples/serialbus/can/mainwindow.h
@@ -74,6 +74,9 @@ private Q_SLOTS:
void disconnectDevice();
void framesWritten(qint64);
+protected:
+ void closeEvent(QCloseEvent *event);
+
private:
void showStatusMessage(const QString &message);
void initActionsConnections();
diff --git a/examples/serialbus/can/mainwindow.ui b/examples/serialbus/can/mainwindow.ui
index 9700024..3db4218 100644
--- a/examples/serialbus/can/mainwindow.ui
+++ b/examples/serialbus/can/mainwindow.ui
@@ -26,7 +26,10 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
- <string>ID (hex)</string>
+ <string>&amp;ID (hex)</string>
+ </property>
+ <property name="buddy">
+ <cstring>idEdit</cstring>
</property>
</widget>
</item>
@@ -49,7 +52,7 @@
<item>
<widget class="QRadioButton" name="dataFrame">
<property name="text">
- <string>Data</string>
+ <string>D&amp;ata</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -66,7 +69,7 @@
<item>
<widget class="QRadioButton" name="errorFrame">
<property name="text">
- <string>Error</string>
+ <string>&amp;Error</string>
</property>
</widget>
</item>
@@ -76,7 +79,7 @@
<item row="0" column="3">
<widget class="QCheckBox" name="fdBox">
<property name="text">
- <string>Flexible Data-Rate
+ <string>&amp;Flexible Data-Rate
(64 byte payload)</string>
</property>
</widget>
@@ -88,7 +91,7 @@
Otherwise, the standard format with 11 bit idenfier is used.</string>
</property>
<property name="text">
- <string>Extended Frame
+ <string>E&amp;xtended Frame
(29 bit identifier)</string>
</property>
</widget>
@@ -96,7 +99,7 @@ Otherwise, the standard format with 11 bit idenfier is used.</string>
<item row="2" column="3">
<widget class="QPushButton" name="sendButton">
<property name="text">
- <string>send</string>
+ <string>&amp;Send</string>
</property>
</widget>
</item>
@@ -110,7 +113,10 @@ Otherwise, the standard format with 11 bit idenfier is used.</string>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
- <string>Data (hex)</string>
+ <string>&amp;Data (hex)</string>
+ </property>
+ <property name="buddy">
+ <cstring>lineEdit</cstring>
</property>
</widget>
</item>
@@ -161,7 +167,7 @@ Otherwise, the standard format with 11 bit idenfier is used.</string>
<x>0</x>
<y>0</y>
<width>551</width>
- <height>25</height>
+ <height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuCalls">
@@ -175,7 +181,7 @@ Otherwise, the standard format with 11 bit idenfier is used.</string>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
- <string>Help</string>
+ <string>&amp;Help</string>
</property>
<addaction name="actionAboutQt"/>
</widget>
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp
index ca666cf..920b2c0 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.cpp
+++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp
@@ -208,13 +208,15 @@ bool PeakCanBackendPrivate::open()
const int bitrate = q->configurationParameter(QCanBusDevice::BitRateKey).toInt();
const int bitrateCode = bitrateCodeFromBitrate(bitrate);
- if (TPCANStatus st = ::CAN_Initialize(channelIndex, bitrateCode, 0, 0, 0) != PCAN_ERROR_OK) {
+ const TPCANStatus st = ::CAN_Initialize(channelIndex, bitrateCode, 0, 0, 0);
+ if (st != PCAN_ERROR_OK) {
q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
return false;
}
if (!acquireReadNotification()) {
- if (TPCANStatus st = ::CAN_Uninitialize(channelIndex) != PCAN_ERROR_OK)
+ const TPCANStatus st = ::CAN_Uninitialize(channelIndex);
+ if (st != PCAN_ERROR_OK)
q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
return false;
}
@@ -235,8 +237,9 @@ void PeakCanBackendPrivate::close()
writeNotifier = nullptr;
}
- if (TPCANStatus st = ::CAN_Uninitialize(channelIndex) != PCAN_ERROR_OK)
- emit q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
+ const TPCANStatus st = ::CAN_Uninitialize(channelIndex);
+ if (st != PCAN_ERROR_OK)
+ q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
isOpen = false;
}
@@ -249,7 +252,8 @@ bool PeakCanBackendPrivate::setConfigurationParameter(int key, const QVariant &v
case QCanBusDevice::BitRateKey:
return verifyBitRate(value.toInt());
default:
- q->setError(PeakCanBackend::tr("Unsupported configuration key"), QCanBusDevice::ConfigurationError);
+ q->setError(PeakCanBackend::tr("Unsupported configuration key: %1").arg(key),
+ QCanBusDevice::ConfigurationError);
return false;
}
}
@@ -355,7 +359,8 @@ void PeakCanBackendPrivate::startWrite()
else
::memcpy(message.DATA, payload.constData(), sizeof(message.DATA));
- if (TPCANStatus st = ::CAN_Write(channelIndex, &message) != PCAN_ERROR_OK)
+ const TPCANStatus st = ::CAN_Write(channelIndex, &message);
+ if (st != PCAN_ERROR_OK)
q->setError(systemErrorString(st), QCanBusDevice::WriteError);
else
emit q->framesWritten(qint64(1));
@@ -378,8 +383,9 @@ bool PeakCanBackendPrivate::acquireReadNotification()
}
#endif
- if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle))
- != PCAN_ERROR_OK) {
+ const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT,
+ &readHandle, sizeof(readHandle));
+ if (st != PCAN_ERROR_OK) {
q->setError(systemErrorString(st), QCanBusDevice::ReadError);
return false;
}
@@ -397,7 +403,8 @@ void PeakCanBackendPrivate::releaseReadNotification()
Q_Q(PeakCanBackend);
quint32 value = 0;
- if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)) != PCAN_ERROR_OK)
+ const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value));
+ if (st != PCAN_ERROR_OK)
q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
if (readNotifier) {
@@ -428,7 +435,8 @@ void PeakCanBackendPrivate::startRead()
TPCANTimestamp timestamp;
::memset(&timestamp, 0, sizeof(timestamp));
- if (TPCANStatus st = ::CAN_Read(channelIndex, &message, &timestamp) != PCAN_ERROR_OK) {
+ const TPCANStatus st = ::CAN_Read(channelIndex, &message, &timestamp);
+ if (st != PCAN_ERROR_OK) {
if (st != PCAN_ERROR_XMTFULL)
q->setError(systemErrorString(st), QCanBusDevice::ReadError);
break;
@@ -489,10 +497,8 @@ bool PeakCanBackend::open()
Q_D(PeakCanBackend);
if (!d->isOpen) {
- if (!d->open()) {
- close(); // sets UnconnectedState
+ if (!d->open())
return false;
- }
// apply all stored configurations except bitrate, because
// the bitrate can not be applied after opening of device
diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp
index 43640cc..f1d7c5c 100644
--- a/src/plugins/canbus/tinycan/tinycanbackend.cpp
+++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp
@@ -171,21 +171,30 @@ bool TinyCanBackendPrivate::open()
{
Q_Q(TinyCanBackend);
- char options[] = "AutoConnect=1;AutoReopen=0";
- if (int ret = ::CanSetOptions(options) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- return false;
+ {
+ char options[] = "AutoConnect=1;AutoReopen=0";
+ const int ret = ::CanSetOptions(options);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ return false;
+ }
}
- if (int ret = ::CanDeviceOpen(channelIndex, nullptr) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- return false;
+ {
+ const int ret = ::CanDeviceOpen(channelIndex, nullptr);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ return false;
+ }
}
- if (int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- ::CanDeviceClose(channelIndex);
- return false;
+ {
+ const int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ ::CanDeviceClose(channelIndex);
+ return false;
+ }
}
isOpen = true;
@@ -196,7 +205,8 @@ void TinyCanBackendPrivate::close()
{
Q_Q(TinyCanBackend);
- if (int ret = ::CanDeviceClose(channelIndex) < 0)
+ const int ret = ::CanDeviceClose(channelIndex);
+ if (ret < 0)
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
isOpen = false;
@@ -210,7 +220,8 @@ bool TinyCanBackendPrivate::setConfigurationParameter(int key, const QVariant &v
case QCanBusDevice::BitRateKey:
return setBitRate(value.toInt());
default:
- q->setError(TinyCanBackend::tr("Unsupported configuration key"), QCanBusDevice::ConfigurationError);
+ q->setError(TinyCanBackend::tr("Unsupported configuration key: %1").arg(key),
+ QCanBusDevice::ConfigurationError);
return false;
}
}
@@ -354,7 +365,8 @@ void TinyCanBackendPrivate::startWrite()
const qint32 messagesToWrite = 1;
::memcpy(message.Data.Bytes, payload.constData(), sizeof(message.Data.Bytes));
- if (int ret = ::CanTransmit(channelIndex, &message, messagesToWrite) < 0)
+ const int ret = ::CanTransmit(channelIndex, &message, messagesToWrite);
+ if (ret < 0)
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::WriteError);
else
emit q->framesWritten(messagesToWrite);
@@ -387,7 +399,8 @@ void TinyCanBackendPrivate::startRead()
::memset(&message, 0, sizeof(message));
const int messagesToRead = 1;
- if (int ret = ::CanReceive(channelIndex, &message, messagesToRead) < 0) {
+ const int ret = ::CanReceive(channelIndex, &message, messagesToRead);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ReadError);
TDeviceStatus status;
@@ -429,7 +442,8 @@ void TinyCanBackendPrivate::startupDriver()
Q_Q(TinyCanBackend);
if (driverRefCount == 0) {
- if (int ret = ::CanInitDriver(nullptr) < 0) {
+ const int ret = ::CanInitDriver(nullptr);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
return;
}
@@ -469,7 +483,8 @@ bool TinyCanBackendPrivate::setBitRate(int bitrate)
}
if (isOpen) {
- if (int ret = ::CanSetSpeed(channelIndex, bitrateCode) < 0) {
+ const int ret = ::CanSetSpeed(channelIndex, bitrateCode);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConfigurationError);
return false;
}
diff --git a/src/serialbus/doc/src/peakcan.qdoc b/src/serialbus/doc/src/peakcan.qdoc
index 4ab8760..3b18393 100644
--- a/src/serialbus/doc/src/peakcan.qdoc
+++ b/src/serialbus/doc/src/peakcan.qdoc
@@ -31,7 +31,7 @@
\brief Overview of how to use the PeakCAN backend.
The PeakCAN backend encapsulates the low-level API to work with the
- \l{http://www.peak-system.com/}{PCAN} adapters.
+ \l{http://www.peak-system.com/}{PEAK-System} CAN adapters.
\section1 Creating CAN Bus Devices
@@ -46,23 +46,22 @@
}
\endcode
- Where, \e peakcan is the backend name.
+ Where \e peakcan is the backend name.
- Further, it is necessary to request from QCanBus the device with the active PeakCan
- interface:
+ Next, a connection to a specific interface can be established:
\code
QCanBusDevice *device = QCanBus::instance()->createDevice("peakcan", QStringLiteral("usbbus1"));
device->connectDevice();
\endcode
- Where, \e usbbus1 is the active CAN interface name. The PCAN API support eight USB
- interfaces from \e usbbus1 to \e usbbus8 and eight PCI interfaces from \e pcibus1 to
- \e pcibus8.
+ Where \e usbbus1 is the active CAN interface name. The PeakCAN backend supports
+ eight USB interfaces from \e usbbus1 to \e usbbus8 and eight PCI interfaces from
+ \e pcibus1 to \e pcibus8.
\note Only the USB and PCI adapters are currently supported by this backend.
- The device is now open and can be written and read:
+ The device is now open for writing and reading CAN frames:
\code
QCanBusFrame frame;
@@ -88,7 +87,7 @@
\li Configuration parameter key
\li Description
\row
- \li QDCanBusDevice::BitRateKey
+ \li QCanBusDevice::BitRateKey
\li Determines the bit rate of the CAN bus connection. The following bit rates
are supported: 5000, 10000, 20000, 33000, 47000, 50000, 83000, 95000,
100000, 125000, 250000, 500000, 800000, 1000000. Note that this configuration
diff --git a/src/serialbus/doc/src/qtcanbus-backends.qdoc b/src/serialbus/doc/src/qtcanbus-backends.qdoc
index 6f32c5e..a2f504e 100644
--- a/src/serialbus/doc/src/qtcanbus-backends.qdoc
+++ b/src/serialbus/doc/src/qtcanbus-backends.qdoc
@@ -60,11 +60,11 @@
\row
\li PEAK-System
\li \l {Using PeakCAN Backend}{PeakCAN} (\c peakcan)
- \li CAN bus backend using the PCAN adapters.
+ \li CAN bus backend using the PEAK CAN adapters.
\row
\li MHS Elektronik
\li \l {Using TinyCAN Backend}{TinyCAN} (\c tinycan)
- \li CAN bus backend using the Tiny-CAN adapters.
+ \li CAN bus backend using the MHS CAN adapters.
\endtable
\section1 Implementing a Custom CAN Plugin
diff --git a/src/serialbus/doc/src/socketcan.qdoc b/src/serialbus/doc/src/socketcan.qdoc
index 4a10ac7..a979103 100644
--- a/src/serialbus/doc/src/socketcan.qdoc
+++ b/src/serialbus/doc/src/socketcan.qdoc
@@ -47,20 +47,19 @@
}
\endcode
- Where, \e socketcan is the backend name.
+ Where \e socketcan is the backend name.
- Further, it is necessary to request from QCanBus the device with the active SocketCAN
- interface:
+ Next, a connection to a specific interface can be established:
\code
QCanBusDevice *device = QCanBus::instance()->createDevice("socketcan", QStringLiteral("can0"));
device->connectDevice();
\endcode
- Where, \e can0 is the active CAN interface name. CAN interfaces act like regular network interfaces
- on Linux systems and can be discovered using \c ifconfig.
+ Where \e can0 is the active CAN interface name. CAN interfaces act like regular
+ network interfaces on Linux systems and can be discovered using \c ifconfig.
- The device is now open and can be written and read:
+ The device is now open for writing and reading CAN frames:
\code
QCanBusFrame frame;
@@ -106,7 +105,8 @@
\row
\li QCanBusDevice::BitRateKey
\li This configuration is not supported by the socketcan backend. However
- it is possible to set the rate when configuring the CAN network interface using the \c {ip link} command.
+ it is possible to set the rate when configuring the CAN network interface using
+ the \c {ip link} command.
\row
\li QCanBusDevice::CanFdKey
\li This configuration option determines whether CANFD frames may be sent or received.
@@ -118,5 +118,5 @@
\snippet snippetmain.cpp SocketCan Filter Example
- Efficient frame format and flexible data-rate are supported in SocketCAN.
+ Extended frame format and flexible data-rate are supported in SocketCAN.
*/
diff --git a/src/serialbus/doc/src/tinycan.qdoc b/src/serialbus/doc/src/tinycan.qdoc
index c5156e4..da45775 100644
--- a/src/serialbus/doc/src/tinycan.qdoc
+++ b/src/serialbus/doc/src/tinycan.qdoc
@@ -31,7 +31,7 @@
\brief Overview of how to use the TinyCAN backend.
The TinyCAN backend encapsulates the low-level API to work with the
- \l{http://www.mhs-elektronik.de/}{Tiny-CAN} adapters.
+ \l{http://www.mhs-elektronik.de/}{MHS Elektronik} CAN adapters.
\section1 Creating CAN Bus Devices
@@ -46,22 +46,21 @@
}
\endcode
- Where, \e tinycan is the backend name.
+ Where \e tinycan is the backend name.
- Further, it is necessary to request from QCanBus the device with the active Tiny-CAN
- interface:
+ Next, a connection to a specific interface can be established:
\code
QCanBusDevice *device = QCanBus::instance()->createDevice("tinycan", QStringLiteral("channela"));
device->connectDevice();
\endcode
- Where, \e channela is the active CAN interface name. The Tiny-CAN API provides only two
- interfaces \e channela and \e channelb.
+ Where \e channela is the active CAN interface name. The TinyCAN backend
+ provides two interfaces, \e channela and \e channelb.
\note Only the USB adapters are currently supported by this backend.
- The device is now open and can be written and read:
+ The device is now open for writing and reading CAN frames:
\code
QCanBusFrame frame;
@@ -79,7 +78,7 @@
QCanBusFrame frame = device->readFrame();
\endcode
- Tiny-CAN supports the following configurations that can be controlled through
+ TinyCAN supports the following configurations that can be controlled through
\l {QCanBusDevice::}{setConfigurationParameter()}:
\table
@@ -87,7 +86,7 @@
\li Configuration parameter key
\li Description
\row
- \li QDCanBusDevice::BitRateKey
+ \li QCanBusDevice::BitRateKey
\li Determines the bit rate of the CAN bus connection. The following bit rates
are supported: 10000, 20000, 50000, 100000, 125000, 250000, 500000, 800000, 1000000.
\endtable
diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp
index a08a339..00505bf 100644
--- a/src/serialbus/qcanbusdevice.cpp
+++ b/src/serialbus/qcanbusdevice.cpp
@@ -42,8 +42,6 @@
#include <QtCore/qdebug.h>
#include <QtCore/qdatastream.h>
-#define SOCKET_CAN_MTU 72
-
QT_BEGIN_NAMESPACE
/*!
@@ -298,8 +296,7 @@ bool QCanBusDevice::hasOutgoingFrames() const
\sa configurationParameter()
*/
-void QCanBusDevice::setConfigurationParameter(int key,
- const QVariant &value)
+void QCanBusDevice::setConfigurationParameter(int key, const QVariant &value)
{
Q_D(QCanBusDevice);
@@ -523,8 +520,11 @@ bool QCanBusDevice::connectDevice()
{
Q_D(QCanBusDevice);
- if (d->state != QCanBusDevice::UnconnectedState)
+ if (d->state != QCanBusDevice::UnconnectedState) {
+ setError(tr("Can not connect an already connected device"),
+ QCanBusDevice::ConnectionError);
return false;
+ }
setState(ConnectingState);
@@ -545,6 +545,14 @@ bool QCanBusDevice::connectDevice()
*/
void QCanBusDevice::disconnectDevice()
{
+ Q_D(QCanBusDevice);
+
+ if (d->state == QCanBusDevice::UnconnectedState
+ || d->state == QCanBusDevice::ClosingState) {
+ qWarning("Can not disconnect an unconnected device");
+ return;
+ }
+
setState(QCanBusDevice::ClosingState);
//Unconnected is set by backend -> might be delayed by event loop
diff --git a/src/tools/canbusutil/readtask.cpp b/src/tools/canbusutil/readtask.cpp
index bb9b344..a83586e 100644
--- a/src/tools/canbusutil/readtask.cpp
+++ b/src/tools/canbusutil/readtask.cpp
@@ -58,16 +58,19 @@ void ReadTask::checkMessages() {
if (frame.frameType() == QCanBusFrame::ErrorFrame) {
view = canDevice->interpretErrorFrame(frame);
} else {
- view += QLatin1String("Id: ");
- view += QString::number(id, 16);
+ const char *format =
+ frame.hasExtendedFrameFormat() ? "Id: %08X" : "Id: %03X";
+ view += QString::asprintf(format, static_cast<uint>(id));
view += QLatin1String(" bytes: ");
view += QString::number(dataLength, 10);
- view += QLatin1String(" data:");
- QByteArray array = frame.payload();
- for (int i=0; i < array.size(); i++) {
- view += QLatin1String(" 0x");
- quint8 number = array[i];
- view += QString::number(number, 16);
+ if (frame.frameType() != QCanBusFrame::RemoteRequestFrame) {
+ view += QLatin1String(" data:");
+ QByteArray array = frame.payload();
+ for (int i=0; i < array.size(); i++) {
+ view += QLatin1String(" 0x");
+ quint8 number = array[i];
+ view += QString::number(number, 16);
+ }
}
}