FastApi с потоком
This commit is contained in:
parent
5e89b12fd6
commit
484e04d0bb
14
ard.py
14
ard.py
@ -1,12 +1,18 @@
|
|||||||
from serial import Serial
|
from serial import Serial
|
||||||
|
import threading
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
ser = Serial('COM5', 9600)
|
s=""
|
||||||
s = ser.read(1) # read up to one hundred bytes
|
|
||||||
print(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 = FastAPI()
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
return ("message", s)
|
return ("message", s)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user