The CanBus object represents the CAN bus attached to the device and allows communication with other devices on the bus.
This object was introduced in InCore 2.0.
- › Inherits
Object <object_Object>
bitRate <property_CanBus_bitRate>
busStatus <property_CanBus_busStatus>
currentFrame <property_CanBus_currentFrame>
error <property_CanBus_error>
errorFilter <property_CanBus_errorFilter>
errorString <property_CanBus_errorString>
loopback <property_CanBus_loopback>
pipes <property_CanBus_pipes>
rawFilters <property_CanBus_rawFilters>
receiveOwnKey <property_CanBus_receiveOwnKey>
resetDelay <property_CanBus_resetDelay>
state <property_CanBus_state>
Object.objectId <property_Object_objectId>
Object.parent <property_Object_parent>
clear() <method_CanBus_clear>
pollBusStatus() <method_CanBus_pollBusStatus>
reset() <method_CanBus_reset>
writeFrame() <method_CanBus_writeFrame>
Object.deserializeProperties() <method_Object_deserializeProperties>
Object.fromJson() <method_Object_fromJson>
Object.serializeProperties() <method_Object_serializeProperties>
Object.toJson() <method_Object_toJson>
errorOccurred() <signal_CanBus_errorOccurred>
frameReceived() <signal_CanBus_frameReceived>
pipesDataChanged() <signal_CanBus_pipesDataChanged>
rawFiltersDataChanged() <signal_CanBus_rawFiltersDataChanged>
Object.completed() <signal_Object_completed>
BusStatus <enum_CanBus_BusStatus>
Error <enum_CanBus_Error>
State <enum_CanBus_State>
single: bitRate
This property holds the CAN bitrate in bits per second.
- › Type
SignedInteger
- › Default
250000
- › Attributes
Writable
single: busStatus
This property holds the current CAN bus status.
This property was introduced in InCore 2.2.
- › Type
BusStatus <enum_CanBus_BusStatus>
- › Signal
busStatusChanged()
- › Attributes
Readonly, Requires
Polling <object_Polling>
single: currentFrame
This property holds the CAN frame which has been received most recently. This property is updated automatically whenever new frames are received. Every frame should therefore be processsed in a handler for the frameReceived() <signal_CanBus_frameReceived>
or currentFrameChanged() <signal_CanBus_currentFrameChanged>
signals immediately.
- › Type
CanFrame <object_CanFrame>
- › Signal
currentFrameChanged()
- › Attributes
Readonly
single: error
This property holds the most recently occurred error or CanBus.NoError <enumitem_CanBus_NoError>
if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() <signal_CanBus_errorOccurred>
signal to detect multiple occurrences of the same error.
- › Type
Error <enum_CanBus_Error>
- › Signal
errorChanged()
- › Attributes
Readonly
single: errorFilter
This property holds the type of error that should be forwarded via the current connection.
- › Type
CanFrame.Errors <enum_CanFrame_Errors>
- › Signal
errorFilterChanged()
- › Attributes
Writable
single: errorString
This property holds the current human readable error string corresponding to the current value in the error <property_CanBus_error>
property. It may include additional information such as failure reasons or locations.
- › Type
String
- › Signal
errorStringChanged()
- › Attributes
Readonly
single: loopback
This property holds whether the CAN bus should operate in loopback mode. Loopback means, whenever a CAN frame is transmitted on the CAN bus, a local echo of this frame is sent to all applications connected to this CAN device.
- › Type
Boolean
- › Signal
loopbackChanged()
- › Attributes
Writable
single: pipes
This property holds a list of CAN communication pipes to operate on the bus. Any incoming CAN frames processed by one or multiple attached pipes will not be available through the currentFrame <property_CanBus_currentFrame>
property. See CanPipe <object_CanPipe>
for details.
- › Type
List <object_List>
<CanPipe <object_CanPipe>
>- › Signal
pipesChanged()
- › Attributes
Readonly
single: rawFilters
This property holds a list of CAN filters used for filtering CAN frames received on the bus. See CanFilter <object_CanFilter>
for details.
- › Type
List <object_List>
<CanFilter <object_CanFilter>
>- › Signal
rawFiltersChanged()
- › Attributes
Readonly
single: receiveOwnKey
This property holds whether the CAN device receives its own send frames. This can be used to check if the transmission was successful.
- › Type
Boolean
- › Signal
receiveOwnKeyChanged()
- › Attributes
Writable
single: resetDelay
This property holds the number of milliseconds after which to reset the bus in case of a bus-off condition.
- › Type
SignedInteger
- › Default
1000
- › Attributes
Writable
single: state
This property holds the current state of the CAN bus.
- › Type
State <enum_CanBus_State>
- › Signal
stateChanged()
- › Attributes
Readonly
single: clear
This method Clears the devices input and output buffers. This function only operates on CanBus <object_CanBus>
buffers. Frames that are already written to the CAN driver or CAN hardware layer, or that are not yet read from these layers, are not cleared by this function.
single: pollBusStatus
This method polls the busStatus <property_CanBus_busStatus>
property. It is called automatically when using a Polling <object_Polling>
property modifier on this property and usually does not have to be called manually.
single: reset
This method performs a CAN controller reset to release the CAN controller from bus off state, if possible.
Note: CAN controller resets disturb the running communication and may take up to one second to complete. Only call this function to recover from bus errors.
This method was introduced in InCore 2.2.
single: writeFrame
This method Writes frame to the CAN bus and returns true
on success; otherwise false
. If an error occurs the errorOccurred() <signal_CanBus_errorOccurred>
signal is emitted.
As per CAN bus specification, frames of type remote transfer request (RTR) do not have a payload, but a length from 0 to 8 (including). This length indicates the expected response payload length from the remote party. Therefore when sending a RTR frame using this function it may still be required to set an arbitrary payload on frame. The length of the arbitrary payload is what is set as size expectation for the RTR frame.
- › Returns
Boolean
single: errorOccurred
This signal is emitted whenever an error has occurred, regardless of whether the error <property_CanBus_error>
property has changed or not. In contrast to the change notification signal of the error <property_CanBus_error>
property this signal is also emitted several times if a certain error occurs several times in succession.
single: frameReceived
This signal is emitted whenever a CAN frame has been received and is available in the currentFrame <property_CanBus_currentFrame>
property. React to this signal or currentFrameChanged() <signal_CanBus_currentFrameChanged>
immediately in order to handle the received data since currentFrame <property_CanBus_currentFrame>
can be updated again at any time.
single: pipesDataChanged
This signal is emitted whenever the List.dataChanged() <signal_List_dataChanged>
signal is emitted, i.e. the item at index
in the pipes <property_CanBus_pipes>
list itself emitted the dataChanged() signal.
single: rawFiltersDataChanged
This signal is emitted whenever the List.dataChanged() <signal_List_dataChanged>
signal is emitted, i.e. the item at index
in the rawFilters <property_CanBus_rawFilters>
list itself emitted the dataChanged() signal.
single: BusStatus
This enumeration describes all possible states of the CAN bus.
This enumeration was introduced in InCore 2.2.
single: CanBus.Unknown
single: CanBus.Good
single: CanBus.Warning
single: CanBus.Error
single: CanBus.BusOff
Name | Value | Description |
---|---|---|
CanBus.Unknown |
0 |
The CAN bus status is unknown. |
CanBus.Good |
1 |
The CAN controller is fully operational. |
CanBus.Warning |
2 |
The CAN controller is in warning status. |
CanBus.Error |
3 |
The CAN controller is in error status (no longer sending CAN frames). |
CanBus.BusOff |
4 |
The CAN controller is in bus off status (disconnected from the CAN bus). |
single: Error
This enumeration describes all errors which can occur in CanBus objects. The most recently occurred error is stored in the error <property_CanBus_error>
property.
single: CanBus.NoError
single: CanBus.ReadError
single: CanBus.WriteError
single: CanBus.ConnectionError
single: CanBus.ConfigurationError
single: CanBus.WriteFrameDataError
single: CanBus.UnknownError
Name | Value | Description |
---|---|---|
CanBus.NoError |
0 |
No error occurred or was detected. |
CanBus.ReadError |
1 |
An error occurred during a read operation. |
CanBus.WriteError |
2 |
An error occurred during a write operation. |
CanBus.ConnectionError |
3 |
An error occurred while attempting to open the CAN bus. |
CanBus.ConfigurationError |
4 |
An error occurred when attempting to set a configuration parameter. |
CanBus.WriteFrameDataError |
5 |
An invalid frame was passed to writeFrame(). |
CanBus.UnknownError |
6 |
An unknown error occurred. |
single: State
This enumeration describes all possible states of the CAN device connection.
single: CanBus.UnconnectedState
single: CanBus.ConnectingState
single: CanBus.ConnectedState
single: CanBus.ClosingState
Name | Value | Description |
---|---|---|
CanBus.UnconnectedState |
0 |
The device is disconnected. |
CanBus.ConnectingState |
1 |
Connecting to the device. |
CanBus.ConnectedState |
2 |
The device is connected. |
CanBus.ClosingState |
3 |
Closing device connection. |
import InCore.Foundation 2.5
import InCore.IO 2.5
Application {
CanBus {
id: bus
onFrameReceived: {
if( currentFrame.frameId === temperatureFrame.frameId )
{
console.log("Remote device temperature:", parseFloat(currentFrame.payload.string))
}
else
{
console.log("Received CAN frame with ID", currentFrame.frameId, "and payload", currentFrame.payload.hex)
}
}
}
CanFrame {
id: testFrame
payload.data: [ 0xde, 0xad, 0xbe, 0xef ]
}
CanFrame {
id: temperatureFrame
frameId: 1
}
System {
id: system
Polling on deviceTemperature { }
}
Timer {
onTriggered: {
testFrame.frameId = 100 + Math.floor(Math.random() * 100)
bus.writeFrame(testFrame)
temperatureFrame.payload.string = system.deviceTemperature.toString()
bus.writeFrame(temperatureFrame)
}
}
}