Object Buffers¶
Support for accessing Object Buffers.
New in version 1.22.
- class canlib.canlib.objbuf.MessageFilter(code, mask)[source]¶
A message reception filter.
First set the mask bit to ‘1’ for the bits you would like to filter on. Then set the code to the desired bitpattern. See Code and Mask Format for an explanation of the code and mask format.
Calling the
MessageFilter
with an id returnsTrue
if the id passes the filter.>>> mf = MessageFilter(code=0b0100, mask=0b0110) >>> mf(0b0110) False
>>> mf(0b0101) True
>>> mf(0b0010) False
For use with
Response
object buffers.New in version 1.22.
- class canlib.canlib.objbuf.Periodic(ch, period_us, frame=None)[source]¶
Periodic object buffer (also known as auto transmit buffer).
Returned from
canlib.Channel.allocate_periodic_objbuf()
- disable()¶
Disable this object buffer.
- free()¶
Deallocate this object buffer.
This object buffer can not be referenced after this operation. To free all allocated object buffers, use
canlib.Channel.free_objbuf()
.
- send_burst(length)[source]¶
Send a burst of CAN frames from this object buffer.
The frames will be sent as fast as possible from the hardware. This function is intended for certain diagnostic applications.
- Parameters
length (
int
) – Number of CAN frames to send.
- set_frame(frame)¶
Define the CAN frame to be sent by the object buffer.
- Parameters
frame (
Frame
) – The CAN frame to send.
- set_msg_count(count)[source]¶
Limit the total number of CAN frames sent.
When this periodic buffer is enabled, only
count
number of CAN frames will be sent (i.e. the periodic buffer will only be active forcount
number of periods).When all frames have been sent, the msg_count is set to zero. If you would like to send five more frames, you need to make two calls:
>>> periodic_buffer.set_msg_count(5) >>> periodic_buffer.enable()
- Parameters
count (
int
) – Total number of CAN frames to send, Zero means infinite.
- class canlib.canlib.objbuf.Response(ch, filter=None, frame=None, rtr_only=False)[source]¶
Auto response object buffer.
Returned from
canlib.Channel.allocate_response_objbuf()
The following example responds with a CAN frame with CAN ID 200 when a CAN frame with CAN ID 100 is received.:
>>> from canlib import canlib, Frame >>> ch = canlib.openChannel(0) >>> msg_filter = canlib.objbuf.MessageFilter(code=100, mask=0xFFFF) >>> msg_filter(100) True >>> frame = Frame(id_=200, data=[1, 2, 3, 4]) >>> response_buf = ch.allocate_response_objbuf(filter=msg_filter, frame=frame) >>> response_buf.enable()
New in version 1.22.
- disable()¶
Disable this object buffer.
- enable()¶
Enable this object buffer.
- free()¶
Deallocate this object buffer.
This object buffer can not be referenced after this operation. To free all allocated object buffers, use
canlib.Channel.free_objbuf()
.
- set_filter(filter)[source]¶
Set message reception filter.
If no filter is set, any CAN ID will trigger the auto response.
- Parameters
filter (
MessageFilter
) – Messages not matching the filter is ignored.
- set_frame(frame)¶
Define the CAN frame to be sent by the object buffer.
- Parameters
frame (
Frame
) – The CAN frame to send.
- set_rtr_only(value)[source]¶
Filter on CAN RTR (remote transmission request).
This complements the message reception filter (see
set_filter()
).When set to
True
, the auto response buffer will only respond to remote requests (that also passes the message reception filter). When set toFalse
, the auto response buffer will respond to both remote requests and ordinary data frames (that also passes the message reception filter).