CanBusProxy
Inherits:
QObject
Sends and receives complete Qt CAN frames on one SocketCAN interface.
Proxies returned by CanBusFactory begin disconnected. The caller explicitly connects and disconnects them and controls their QObject lifetime. Transmit and receive delivery can be paused independently without disconnecting. Received frames count as bus activity even while receive delivery is paused. Activity starts after the first frame and expires after five seconds of silence by default; applications may override that interval with setActivityTimeout(). Disconnecting stops the activity timer and clears activity, emitting activityChanged(false) if the proxy was active.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
~CanBusProxy override | ||
QString | interfaceName const | Returns the SocketCAN interface name owned by this proxy. |
QCanBusDevice::CanBusDeviceState | state const | Returns the underlying Qt SerialBus connection state. |
QCanBusDevice::CanBusError | error const | Returns the most recent Qt SerialBus error code. |
QString | errorString const | Returns the most recent Qt SerialBus error description. |
bool | connectBus | Explicitly connects this proxy to its SocketCAN interface. |
void | disconnectBus | Disconnects the interface and clears activity if active. |
bool | sendFrame | Sends a complete Qt CAN frame when transmitting is enabled and connected. |
bool | transmitEnabled const | Returns whether outgoing frame delivery is enabled (initially true). |
void | setTransmitEnabled | Enables or pauses outgoing frames without disconnecting the bus. |
bool | receiveEnabled const | Returns whether incoming frame delivery is enabled (initially true). |
void | setReceiveEnabled | Enables or pauses incoming frame delivery without disconnecting. |
QMetaObject::Connection | listen | Connects a context-bound callback for frames with the given CAN ID. |
bool | isActive const | Returns whether a frame arrived within the current activity window. |
int | activityTimeout const | Returns the inactivity timeout in milliseconds. |
bool | setActivityTimeout | Sets the inactivity timeout in milliseconds. |
override
~CanBusProxy
Section titled “~CanBusProxy”const
interfaceName
Section titled “interfaceName”Returns the SocketCAN interface name owned by this proxy.
const
Returns the underlying Qt SerialBus connection state.
const
Returns the most recent Qt SerialBus error code.
const
errorString
Section titled “errorString”Returns the most recent Qt SerialBus error description.
connectBus
Section titled “connectBus”Explicitly connects this proxy to its SocketCAN interface.
Returns
Section titled “Returns”True when Qt SerialBus successfully opens the interface.
disconnectBus
Section titled “disconnectBus”Disconnects the interface and clears activity if active.
sendFrame
Section titled “sendFrame”Sends a complete Qt CAN frame when transmitting is enabled and connected.
Returns
Section titled “Returns”True when the connected Qt device accepts the frame for transmission.
const
transmitEnabled
Section titled “transmitEnabled”Returns whether outgoing frame delivery is enabled (initially true).
setTransmitEnabled
Section titled “setTransmitEnabled”Enables or pauses outgoing frames without disconnecting the bus.
const
receiveEnabled
Section titled “receiveEnabled”Returns whether incoming frame delivery is enabled (initially true).
setReceiveEnabled
Section titled “setReceiveEnabled”Enables or pauses incoming frame delivery without disconnecting.
Frames received while paused are drained and discarded, while activity is still tracked. Pending frames are drained before delivery is re-enabled.
listen
Section titled “listen”Connects a context-bound callback for frames with the given CAN ID.
Matches data and remote request frames of the specified format; error frames are available through frameReceived instead. Delivery is paused together with frameReceived when receive delivery is disabled. The callback receives the original complete frame, regardless of payload length, and is disconnected when context is destroyed. A null context or empty callback produces an invalid connection.
Returns
Section titled “Returns”A connection that may be explicitly disconnected by the caller.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
frameId | CAN_FRAME_ID | CAN identifier to match. |
format | FrameFormat | Standard or extended CAN identifier format. |
context | QObject* | QObject that owns the callback’s lifetime. |
handler | const std::function<void(const QCanBusFrame&)>& | Callback invoked for matching frames. |
const
isActive
Section titled “isActive”Returns whether a frame arrived within the current activity window.
const
activityTimeout
Section titled “activityTimeout”Returns the inactivity timeout in milliseconds.
Defaults to 5000.
setActivityTimeout
Section titled “setActivityTimeout”Sets the inactivity timeout in milliseconds.
Changing the timeout while active restarts the silence window. Zero is allowed and expires on the next event-loop turn; negative values are rejected without changing the current timeout.
Returns
Section titled “Returns”True when timeoutMs is non-negative.
Signals
Section titled “Signals”| Return | Name | Description |
|---|---|---|
void | stateChanged | Forwarded when the underlying Qt device changes connection state. |
void | errorOccurred | Forwarded when the underlying Qt device reports an error. |
void | frameReceived | Emitted for each received frame when receive delivery is enabled. |
void | activityChanged | Emitted when the activity monitor changes active/inactive state. |
stateChanged
Section titled “stateChanged”Forwarded when the underlying Qt device changes connection state.
errorOccurred
Section titled “errorOccurred”Forwarded when the underlying Qt device reports an error.
frameReceived
Section titled “frameReceived”Emitted for each received frame when receive delivery is enabled.
activityChanged
Section titled “activityChanged”Emitted when the activity monitor changes active/inactive state.
Public Types
Section titled “Public Types”| Name | Description |
|---|---|
FrameFormat | CAN identifier format used when matching received frames. |
FrameFormat
Section titled “FrameFormat”CAN identifier format used when matching received frames.
| Value | Description |
|---|---|
Standard | Standard 11-bit identifier. |
Extended | Extended 29-bit identifier. |