The CanFilter object represents a filter for CAN frames. CAN frame filtering happens at the driver and hardware level and is thus very efficient. This can be used on CAN nodes which need to receive CAN frames for their own frame id only.
This object was introduced in InCore 2.0.
- › Inherits
Object <object_Object>
format <property_CanFilter_format>
frameId <property_CanFilter_frameId>
frameIdMask <property_CanFilter_frameIdMask>
type <property_CanFilter_type>
Object.objectId <property_Object_objectId>
Object.parent <property_Object_parent>
Object.deserializeProperties() <method_Object_deserializeProperties>
Object.fromJson() <method_Object_fromJson>
Object.serializeProperties() <method_Object_serializeProperties>
Object.toJson() <method_Object_toJson>
Object.completed() <signal_Object_completed>
Format <enum_CanFilter_Format>
single: format
This property holds the frame format of the matching CAN bus frame.
- › Type
Format <enum_CanFilter_Format>
- › Default
CanFilter.MatchBaseAndExtendedFormat <enumitem_CanFilter_MatchBaseAndExtendedFormat>
- › Signal
formatChanged()
- › Attributes
Writable
single: frameId
This property holds the frame id used to filter the incoming frames.
The frameId <property_CanFilter_frameId>
is used in conjunction with frameIdMask <property_CanFilter_frameIdMask>
. The matching is successful if the following evaluates to true
:
(receivedFrameId & frameIdMask) == (frameId & frameIdMask)
- › Type
UnsignedInteger
- › Default
0
- › Signal
frameIdChanged()
- › Attributes
Writable
single: frameIdMask
This property holds the bit mask that is applied to the frame id of the filter and the received frame.
The two frame ids are matching if the following evaluates to true
:
(receivedFrameId & frameIdMask) == (frameId & frameIdMask)
- › Type
UnsignedInteger
- › Default
0
- › Signal
frameIdMaskChanged()
- › Attributes
Writable
single: type
This property holds the type of the frame to be filtered. Any CAN bus frame type can be matched by setting this property to CanFrame.InvalidFrame <enumitem_CanFrame_InvalidFrame>
. The filter object is invalid if type is equal to CanFrame.UnknownFrame <enumitem_CanFrame_UnknownFrame>
.
- › Type
CanFrame.Type <enum_CanFrame_Type>
- › Default
CanFrame.InvalidFrame <enumitem_CanFrame_InvalidFrame>
- › Signal
typeChanged()
- › Attributes
Writable
single: Format
This enumeration describes the format pattern, which is used to filter incoming CanFrame <object_CanFrame>
.
single: CanFilter.MatchBaseFormat
single: CanFilter.MatchExtendedFormat
single: CanFilter.MatchBaseAndExtendedFormat
Name | Value | Description |
---|---|---|
CanFilter.MatchBaseFormat |
1 |
The CAN bus frame must use the base frame format (11 bit identifier). |
CanFilter.MatchExtendedFormat |
2 |
The CAN bus frame must use the extended frame format (29 bit identifier). |
CanFilter.MatchBaseAndExtendedFormat |
3 |
The CAN bus frame can have a base or an extended frame format. |
import InCore.Foundation 2.5
import InCore.IO 2.5
Application {
CanBus {
// assume nodes encode their address in bits 8..10 and message type in bits 0..7 of the CAN frame id
// then this configuration will make the bus receive only frames (any message type) from slave 4 and
// error frames from any slave
rawFilters: [
CanFilter {
type: CanFrame.DataFrame
frameId: 4 << 8
frameIdMask: 0xff00
},
CanFilter {
type: CanFrame.ErrorFrame
}
]
onFrameReceived: {
console.log("Received CAN frame with ID", currentFrame.frameId, "and payload", currentFrame.payload.hex)
}
}
}