From 484e04d0bb9be021cbdcce3945b7bde5db372949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Mon, 13 May 2024 20:10:59 +0300 Subject: [PATCH] =?UTF-8?q?FastApi=20=D1=81=20=D0=BF=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ard.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ard.py b/ard.py index 339146a..b958f1d 100644 --- a/ard.py +++ b/ard.py @@ -1,12 +1,18 @@ from serial import Serial +import threading from fastapi import FastAPI -ser = Serial('COM5', 9600) -s = ser.read(1) # read up to one hundred bytes -print(s) +s="" + +ser = Serial('COM4', 9600) +def pot(): + global s + while True: + s = ser.read(1) # read up to one hundred bytes +th=threading.Thread(target=pot) +th.start() app = FastAPI() @app.get("/") async def root(): - return ("message", s) - + return ("message", s) \ No newline at end of file