CanBus¶
Description¶
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 |
---|
Properties¶
bitRate¶
This property holds the CAN bitrate in bits per second.
› Type: | SignedInteger |
---|---|
› Default: | 250000 |
› Attributes: | Writable |
busStatus¶
This property holds the current CAN bus status.
This property was introduced in InCore 2.2.
› Type: | BusStatus |
---|---|
› Signal: | busStatusChanged() |
› Attributes: | Readonly, Requires Polling |
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() or currentFrameChanged() signals immediately.
› Type: | CanFrame |
---|---|
› Signal: | currentFrameChanged() |
› Attributes: | Readonly |
error¶
This property holds the most recently occurred error or CanBus.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
› Type: | Error |
---|---|
› Signal: | errorChanged() |
› Attributes: | Readonly |
errorFilter¶
This property holds the type of error that should be forwarded via the current connection.
› Type: | CanFrame.Errors |
---|---|
› Signal: | errorFilterChanged() |
› Attributes: | Writable |
errorString¶
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
› Type: | String |
---|---|
› Signal: | errorStringChanged() |
› Attributes: | Readonly |
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 |
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. See CanPipe for details.
› Type: | List<CanPipe> |
---|---|
› Signal: | pipesChanged() |
› Attributes: | Readonly |
rawFilters¶
This property holds a list of CAN filters used for filtering CAN frames received on the bus. See CanFilter for details.
› Type: | List<CanFilter> |
---|---|
› Signal: | rawFiltersChanged() |
› Attributes: | Readonly |
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 |
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 |
Methods¶
clear()¶
This method Clears the devices input and output buffers. This function only operates on 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.
pollBusStatus()¶
This method polls the busStatus property. It is called automatically when using a Polling property modifier on this property and usually does not have to be called manually.
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.
writeFrame(Variant frame)¶
This method Writes frame to the CAN bus and returns true
on success; otherwise false
. If an error occurs the 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 |
---|
Signals¶
errorOccurred()¶
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
frameReceived()¶
This signal is emitted whenever a CAN frame has been received and is available in the currentFrame property. React to this signal or currentFrameChanged() immediately in order to handle the received data since currentFrame can be updated again at any time.
pipesDataChanged(SignedInteger index)¶
This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index
in the pipes list itself emitted the dataChanged() signal.
rawFiltersDataChanged(SignedInteger index)¶
This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index
in the rawFilters list itself emitted the dataChanged() signal.
Enumerations¶
BusStatus¶
This enumeration describes all possible states of the CAN bus.
This enumeration was introduced in InCore 2.2.
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). |
Error¶
This enumeration describes all errors which can occur in CanBus objects. The most recently occurred error is stored in the error property.
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. |
State¶
This enumeration describes all possible states of the CAN device connection.
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. |
Example¶
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)
}
}
}