Skip to content

Sending periodically doesn't work even though single messages can be send #58

@hardbyte

Description

@hardbyte

Originally reported by: Sebastian Kienitz (Bitbucket: skienit, GitHub: Unknown)


Hi,

I wonder why I cant use the cyclic send function even though I can send single messages. I have two physical devices connected to each other to proof if its working.

In the following code "send_one()" works perfectly, but "send_cyclic()" doesnt:

#!python

from __future__ import print_function

import can
import time
can.rc['interface'] = 'socketcan_ctypes'
can.rc['channel'] = 'can0'

from can.interfaces.interface import *


def send_one():
    bus = can.interface.Bus(channel='can0' , bustype='socketcan_ctypes')
    msg = can.Message(arbitration_id=0xc0ffee,
                      data=[0, 25, 0, 1, 3, 1, 4, 1],
                      extended_id=False)
    try:
        bus.send(msg)
        print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")


def send_cyclic():
    bus = can.interface.Bus(channel='can0' , bustype='socketcan_ctypes')
    msg = can.Message(arbitration_id=0xc0ffee,
                      data=[0, 25, 0, 1, 3, 1, 4, 1],
                      extended_id=False)
    try:
        can.send_periodic('can0', msg, 0.020)
        print("Message sent periodically on  {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")

if __name__ == "__main__":
    send_one()
    send_cyclic()
    time.sleep(10)


Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions