ValueError:“port”必须是None或字符串,不是

问题描述 投票:-1回答:1

我不明白这个错误,经过5小时寻找解决方案后我终于放弃了。

我正在尝试打开一个串行连接,但显然我的端口不是一个刺痛?

同一个端口可以在不同的代码中正常工作......

NOT WORKING

import serial
import pynextion


class NextionApp:

    def __init__(self):
        ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=0)
        pages = [
            {"id": "0", "name": "page0()page",
                "components": [
                    {"id": "1", "type": "text", "name": "txt_tmp"},
                    {"id": "3", "type": "text", "name": "txt_hum"},
                    {"id": "0", "type": "text", "name": "txt_co2"},
                    {"id": "4", "type": "button", "name": "btn_test"},
                ]
            }
        ]
        self.nextion = pynextion.Nextion(ser, pages)
        print("Serial connected")

nextionApp = NextionApp()

WORKING

#!/usr/bin/env python


import time
import serial


ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=1)
counter=0


while 1:
   x=ser.readline()
   print (x)
python python-3.x raspberry-pi3 pyserial nextion
1个回答
0
投票

Python Nexation库期望接收设备路径作为输入而不是serial对象的实例(它自己创建)。你应该致电:

self.nextion = pynextion.Nextion("/dev/ttyAMA0", pages)
© www.soinside.com 2019 - 2024. All rights reserved.