首页 > 解决方案 > 在 azure edge python 模块中使用 pyserial

问题描述

我正在尝试在使用 azure edge python 模块时从 docker 实现串行通信,似乎 pyserial 不起作用。它无法从 docker 中找到物理设备端口。

{
          "TestPythonModule": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.TestPythonModule}",
              "createOptions": {
                "HostConfig": {
                  "Devices": [
                    {
                      "PathOnHost": "/dev/ttyS0",
                      "PathInContainer": "/dev/ttyS0",
                      "CgroupPermissions": "rwm"
                    }
                  ]
                }

              }
            }
          }
        }
      }
    }

标签: python-3.xpyserialazure-iot-edge

解决方案


您是否通过模块配置中的创建选项将串行端口映射到容器中......像这样:

{
  "HostConfig": {
    "Devices": [
      {
        "PathOnHost": "<device name on host machine>",
        "PathInContainer": "<device name in container>",
        "CgroupPermissions": "rwm"
      }
    ]
  }
}

主机上的设备名称在哪里类似于 /dev/ttys0 或任何串行端口映射到您的机器上?(我假设Linux)


推荐阅读