Skip to content

Timestamp when message is transmitted #2029

Description

@BD-MK

Is your feature request related to a problem? Please describe.

I would like to measure the time it takes for a CAN node to respond to a given message.
Received messages have their timestamp correctly set, however there is no direct way to get the timestamp when a message is transmitted.

As a workaround, I'm using the timestamp when I call bus.send, however this is not necessarily the time when the message is actually transmitted on the bus (up to 30 ms difference).
The timings I'm measuring with this workaround do not match the timings I'm directly recording in the PCAN software.

Describe the solution you'd like

Ideally, the bus.send implementation would override the .timestamp property of the message object I called it with.
By default, the timestamp is 0.0 on newly constructed messages. Calling bus.sent does not immediately cause a transmission but only puts the message into the transmit buffer of the can device. For best results, the can driver implementation should set the correct timestamp once message was actually sent.

msg = can.Message(...)
print(msg.timestamp) # 0.0 - default
bus.send(msg)
print(msg.timestamp) # 0.0 - message given to can device but not physically sent yet
time.sleep(0.5)
print(msg.timestamp) # 1773217081.775475 - can driver sets timestamp property once message was actually transmitted

Describe alternatives you've considered

I have considered setting up a virtual can or configuring some loopback setup, such that i can use the receive timestamps for both received & transmitted messages. However this seems rather complicated for a seemingly simple task.

Activity

  1. Nakakiyo092 commented on Mar 10, 2026

    @Nakakiyo092

    Hello,

    I'm just a user of this library, but let me share something that might be helpful.

    Have you considered using receive_own_messages=True, which is also discussed in #1863?
    As far as I understand, this is the official mechanism to obtain hardware timestamps for transmitted frames.

    I have used this feature with a Vector device, and it worked well for the purpose.
    However, support for this capability would depend on the specific hardware and driver you use.

    Regards.

  2. BD-MK commented on Mar 11, 2026

    @BD-MK
    Author

    @Nakakiyo092 Yes, that should work, thanks for linking the other discussion. I'll have to see if the timings are accurate, but this seems like the best way currently possible with python-can.
    I'll leave this issue open though because I think there is room for a "proper" solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions