hardbyte / hardbyte/python-can

send_periodic not working on RPI Linux 6.1.21-v8+

Abierto
#1,652 7 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
1.6k
Forks
697
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Describe the bug

Receiving the following error when calling `send_periodic()` on RPI (Linux 6.1.21-v8+) using `socketcan` bus: `can.exceptions.CanOperationError: Couldn't send CAN BCM frame due to OS Error: Invalid argument You are probably referring to a non-existing frame. [Error Code 22]`

Full trace:
```sh
python3.9 send_periodic_test.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/can/interfaces/socketcan/socketcan.py", line 275, in send_bcm
return bcm_socket.send(data)
OSError: [Errno 22] Invalid argument

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/pi/send_periodic_test.py", line 9, in
interface.send_periodic(can.Message(arbitration_id=0x18FFFF00, data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]), period=0.1, duration=1.0)
File "/home/pi/.local/lib/python3.9/site-packages/can/bus.py", line 241, in send_periodic
self._send_periodic_internal(msgs, period, duration),
File "/home/pi/.local/lib/python3.9/site-packages/can/interfaces/socketcan/socketcan.py", line 843, in _send_periodic_internal
task = CyclicSendTask(bcm_socket, task_id, msgs, period, duration)
File "/home/pi/.local/lib/python3.9/site-packages/can/interfaces/socketcan/socketcan.py", line 345, in __init__
self._tx_setup(self.messages)
File "/home/pi/.local/lib/python3.9/site-packages/can/interfaces/socketcan/socketcan.py", line 372, in _tx_setup
send_bcm(self.bcm_socket, header + body)
File "/home/pi/.local/lib/python3.9/site-packages/can/interfaces/socketcan/socketcan.py", line 288, in send_bcm
raise can.CanOperationError(base + specific_message, error.errno) from error
can.exceptions.CanOperationError: Couldn't send CAN BCM frame due to OS Error: Invalid argument You are probably referring to a non-existing frame. [Error Code 22]
SocketcanBus was not properly shut down
```

Python script:

```py
import can

interface = can.interface.Bus(
channel='can0',
interface='socketcan',
bitrate=250000
)
interface.send(can.Message(arbitration_id=0x18FFFF00, data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
interface.send_periodic(can.Message(arbitration_id=0x18FFFF00, data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]), period=0.1, duration=1.0)
interface.shutdown()
```

I set up RPI using latest Raspbian version, which is running Linux kernel version `6.1.21-v8+` (using python 3.9) . I am using seeed studio CAN hat with their overlay enabled. I have another RPI running Linux kernel version `5.10.11-v7l+` (using python 3.7) that has been working fine for some time now.

### To Reproduce

Steps I did for a completely fresh install:

1. Install latest Raspbian image or update existing image to Linux 6.1.21-v8+
2. Enable SPI via raspi-config
3. `sudo apt update`
4. `sudo apt upgrade`
5. `sudo apt install can-utils git python3-pip exfat-fuse exfat-utils`
6. `python3 -m pip install python-can RPi.GPIO pigpio pandas numpy`
7. Modify `/etc/network/interfaces` with:

```txt
auto can0
iface can0 inet manual
pre-up /sbin/ip link set $IFACE up type can bitrate 250000 sample-point 0.8 dbitrate 2000000 dsample-point 0.8 fd on
up /sbin/ifconfig $IFACE up
down /sbin/ifconfig $IFACE down

auto can1
iface can1 inet manual
pre-up /sbin/ip link set $IFACE up type can bitrate 250000 sample-point 0.8 dbitrate 2000000 dsample-point 0.8 fd on
up /sbin/ifconfig $IFACE up
down /sbin/ifconfig $IFACE down
```

9. Add `dtoverlay=seeed-can-fd-hat-v1` (using older seeed studio hat without RTC) to `/boot/config.txt`

10. Modify `/etc/rc.local`

```txt
sudo ifconfig can0 txqueuelen 65535
sudo ifconfig can1 txqueuelen 65535
```

11. `sudo reboot`
12. `touch send_periodic_test.py`
13. Add

```py
import can

interface = can.interface.Bus(
channel='can0',
interface='socketcan',
bitrate=250000
)
interface.send(can.Message(arbitration_id=0x18FFFF00, data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
interface.send_periodic(can.Message(arbitration_id=0x18FFFF00, data=[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]), period=0.1, duration=1.0)
interface.shutdown()
```

14. `python3 send_periodic_test.py`

### Expected behavior

`send_periodic` should work as expected on latest Linux kernel.

### Additional context

OS and version: Linux 6.1.21-v8+
Python version: Python 3.9.2
python-can version: 4.2.2
python-can interface/s (if applicable): socketcan

Traceback and logs

```python
def func():
return "hello, world!"
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.