0

I am using python-can in order to send can frames with VN16XX Vector's hardware without relying on CANoe (no licensing needed and we can share the tool with entities that do not have CANoe installed).

The simplest example that I am running in this moment is the following:

import can
import time
from ctypes import c_int, byref, windll
current_res = c_int()

if __name__ == "__main__":
    windll.ntdll.NtSetTimerResolution(5000, True, byref(current_res))
    try:
        bus1 = can.interface.Bus(bustype='vector', app_name='testApp', channel=2, bitrate=500000, fd=True, data_bitrate = 1000000)
    except Exception as e:
        print (e)
        exit()

    msg1 = can.Message(arbitration_id=0x201,
                       data=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
                       extended_id=False, is_fd=True)

    task = bus1.send_periodic(msg1, period=0.010, duration=10)
    assert isinstance(task, can.CyclicSendTaskABC)
    time.sleep(10)
    task.stop()
    print("stopped cyclic send")
    windll.ntdll.NtSetTimerResolution(5000, False, byref(current_res))

Here I use the NtSetTimerResolution to achieve a timer resolution of 500us as told in this answer.

The problem is: there is jitter in the output signal. The external oscilloscope shows up to ± 2 ms of jitter, that is not acceptable for my application.

Here the question(s):

    • How can I reduce the jitter on the output frames?
    • How does Vector achieve precise timings on the output frames? I don't think Vector timers rely on the external hardware because I can create timer instances also for sending UART frames without the VN16xx attached, and the jitter is almos not present also in that case.
    • MAYBE it's related to python overhead? Would switching to Cython provide better performance?

K.R.

Catosh
  • 145
  • 1
  • 9

0 Answers0