标签: python-can

与 docker 容器共享虚拟网络

我正在做一个项目,需要我在我的主机上创建一个虚拟 CAN 网络

$ sudo modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
Run Code Online (Sandbox Code Playgroud)

我的 ifconfig :

在此处输入图片说明

我的问题是如何与我的 docker 容器共享这个接口。

如果它有任何用处,我find / -name "vcan0" -print 2>/dev/null在我的主机上运行以下命令:

/sys/class/net/vcan0
/sys/devices/virtual/net/vcan0
/proc/sys/net/ipv4/conf/vcan0
/proc/sys/net/ipv4/neigh/vcan0
Run Code Online (Sandbox Code Playgroud)

我可以使用docker run --rm -it --network=host ... . 唯一的问题是没有网络隔离 b/w docker 主机和容器了。有没有办法在不共享主机网络的情况下实现上述目标?

linux can-bus docker docker-networking python-can

5
推荐指数
1
解决办法
1164
查看次数

在 CANbus 上接收消息总是返回与 python-can 相同的值

我有一个带有多个输入的 CAN 总线 (PCAN)。我尝试读取 python 中的输入并将其打印在控制台上。我从总线收到的第一条消息是正确的,但是如果我更改输入的状态,消息中的数据不会更改并继续吐出它收到的第一条数据。在PCAN视图中我可以看到数据变化,所以这不是硬件故障。

我的代码:

import can
from time import sleep


def main():
bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)

try:
    while True:

        # msg = can.Message(arbitration_id=0x232, data=[0x00], is_extended_id=False)
        # try:
        #     bus.send(msg)
        #     print("message sent on {}".format(bus.channel_info))
        # except can.CanError:
        #     print("message not sent!")

        msg = bus.recv(None)
        try:

            if msg.arbitration_id == 0x1B2:
                print(msg)

            if msg.arbitration_id == 0x1B3:
                print(msg)

            if msg.arbitration_id == 0x1B4:
                print(msg)

            if msg.arbitration_id == 0x1B5:
                print(msg)

        except AttributeError:
            print("Nothing received this time")

        sleep(0.2)

except KeyboardInterrupt:
    print("Program Exited") …
Run Code Online (Sandbox Code Playgroud)

python-3.x python-can

4
推荐指数
1
解决办法
2万
查看次数

python-can J1939 filter mask

I have been working in a Raspberry with an MCP2515 CAN bus device for read entire values of J1939 messages on broadcasting with python .

I would like to filter the J1939 messages, but i'm not undestand the meaning of the can-mask and how I discorver that. In the docs of python-can says :

All messages that match at least one filter are returned. If filters is None or a zero length sequence, all messages are matched.

[{"can_id": 0x11, "can_mask": …
Run Code Online (Sandbox Code Playgroud)

python can-bus j1939 python-can

4
推荐指数
1
解决办法
2535
查看次数