1

I want to send a message periodically using socketCAN with this device

I created a small script to achieve this which looks like this:

import os
import time

msg = "1FF#FFFFF00000000000"

os.system("sudo slcand -o -c -f -s6 /dev/serial/by-id/*CANtact* can0")
os.system("sudo ifconfig can0 up")
os.system("sudo ifconfig can0 txqueuelen 1000") # this does not help

start = time.time()
while True:
    if round(time.time() - start, 1) % 60 == 0.:
        print(str(int((time.time() - start) / 60)) + " minutes")
    os.system("cansend can0 " + msg)
    time.sleep(0.1)

I was already doing some research and found that for some people it worked to set the txqueuelen. However, that did not help me. The output of this script looks like this:

0 minutes
1 minutes
[...]
15 minutes
16 minutes
18 minutes
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
[and so on]

The device stops sending those messages before that error occurs. The indicator LED for in- and outgoing traffic stops blinking around 10 seconds to a few minutes before error message appears. Also, I cannot read anything on the receiving side. The time it takes until the buffer is full varies gravely, between a few minutes and a few hours. Usually within 10-20 min though.

I had the thought that there might be something like a receiving buffer and because I never read from that that it just fills up. But I do not know whether this is actually the case and also not how to test it or how to flush the buffer or reset it or whatever. I only need to send my messages. I do not care about anything else.

The only solution afterwards is to restart my Raspberry Pi which powers the device.

JRsz
  • 2,891
  • 4
  • 28
  • 44
  • Is there anybody listening in the bus? – Fusho Sep 08 '18 at 14:19
  • No, only my PC at one endpoint and another device receiving those messages. – JRsz Sep 09 '18 at 14:35
  • This looks suspect: `os.system("sudo slcand -o -c -f -s6 /dev/serial/by-id/*CANtact* can0")` - What do you get when you run `lsusb` on your command line terminal? – thewheelz Sep 11 '18 at 22:06

1 Answers1

1

ifconfig-parameters need to be set before you bring up a link, but you bring up the link before setting the parameters. So I'm not sure you actually have a txqueuelen of 1000 when you run the script. An output of your ifconfig can0 might show this.

Try switching the order of the ifconfig-commands.

Instead of:

os.system("sudo ifconfig can0 up")
os.system("sudo ifconfig can0 txqueuelen 1000")`

Do:

os.system("sudo ifconfig can0 txqueuelen 1000")
os.system("sudo ifconfig can0 up")

I would personally also add in a command to bring can0 down when the script ends.

shahin1978
  • 11
  • 3
  • Funnily, I was facing similar issue exactly after 18 minutes using PYUAVCAN, and increasing txqueuelen didn't work. Need to research a little bit more. – Kamiccolo Oct 30 '19 at 18:48