hardbyte / hardbyte/python-can

send_periodic not working on RPI Linux 6.1.21-v8+

Đang mở
#1,652 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
1.6k
Fork
697
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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!"
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.