-1

私はエラーを理解していません.5時間解決策を探した後、私は最終的にあきらめました.

シリアル接続を開こうとしていますが、どうやら私のポートは問題ではないようです。

同じポートが別のコードで正常に動作します...

機能しない

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()

働く

#!/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)
4

1 に答える 1

0

Python Nexation ライブラリは、serialオブジェクトのインスタンスではなく、デバイス パスを入力として受け取ることを想定しています (それ自体を作成します)。あなたは呼び出す必要があります:

self.nextion = pynextion.Nextion("/dev/ttyAMA0", pages)
于 2019-04-27T21:45:04.137 に答える