首页 > 解决方案 > python套接字协议不支持

问题描述

我在 RaspberryPi3 上使用了 python-can-isotp,并使用示例代码对其进行了测试,但出现错误。

我的简单代码:

import isotp

s = isotp.socket()
s2 = isotp.socket()
# Configuring the sockets.
s.set_fc_opts(stmin=5, bs=10)
#s.set_general_opts(...)
#s.set_ll_opts(...)

s.bind("vcan0" rxid=0x123 txid=0x456)  # We love named parameters!
s2.bind("vcan0", rxid=0x456, txid=0x123)
s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.")
print(s.recv())

错误:

File "/usr/local/opt/python-3.7.0/lib/python3.7/socket.py", line 151, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) OSError: [Errno 93] Protocol not supported

有人可以帮我找到问题的解决方案吗?

标签: pythonsocketscan-bus

解决方案


我按照这些说明(稍作修改)isotp使用最新的 Raspbian Stretch 在 Raspberry Pi 3B+ 上工作。

这是我执行的命令的确切顺序:

sudo apt update
sudo apt upgrade
git clone https://github.com/hartkopp/can-isotp.git
cd can-isotp
sudo apt install build-essential raspberrypi-kernel-headers
make install
sudo make modules_install
modprobe can
sudo insmod ./net/can/can-isotp.ko

但是,我不在 Python 中使用它。我只是简单地测试了提供用于使用的工具isotp,例如 egisotpsendisotprecv.


推荐阅读