finnal
This commit is contained in:
@@ -8,7 +8,7 @@ app = FastAPI()
|
||||
|
||||
VIDEO_SAVE_PATH = "/mnt/save/video"
|
||||
IMAGE_SAVE_PATH = "/mnt/save/warning"
|
||||
MODBUS_BIN_PATH = "/home/orangepi/RKApp/ModBus/modbus"
|
||||
MODBUS_BIN_PATH = "/home/orangepi/RKApp/GPIOSignal/bin/sendGpioSignal"
|
||||
|
||||
os.makedirs(VIDEO_SAVE_PATH, exist_ok=True)
|
||||
os.makedirs(IMAGE_SAVE_PATH, exist_ok=True)
|
||||
@@ -88,29 +88,29 @@ async def upload_image(
|
||||
return {"image_saved_to": image_path}
|
||||
|
||||
|
||||
# @app.post("/upload_distance/")
|
||||
# async def upload_distance(
|
||||
# distance: float = Form(..., description="距离")
|
||||
# ):
|
||||
# # 调用本地 modbus 程序,将距离作为参数传递
|
||||
# try:
|
||||
# #写入日志精确到毫秒
|
||||
# # now = datetime.now()
|
||||
# # log_line = f"{now.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]} distance={distance} ts={ts}\n"
|
||||
# # with open("/home/orangepi/Opencv/time.txt", "a") as f:
|
||||
# # f.write(log_line)
|
||||
# result = subprocess.run(
|
||||
# [MODBUS_BIN_PATH, str(int(distance))],
|
||||
# capture_output=True,
|
||||
# text=True,
|
||||
# timeout=5
|
||||
# )
|
||||
# if result.returncode != 0:
|
||||
# return JSONResponse(status_code=500, content={"error": f"modbus程序执行失败: {result.stderr}"})
|
||||
# return {
|
||||
# "distance": distance,
|
||||
# "modbus_output": result.stdout.strip()
|
||||
# }
|
||||
# except Exception as e:
|
||||
# return JSONResponse(status_code=500, content={"error": str(e)})
|
||||
@app.post("/upload_distance/")
|
||||
async def upload_distance(
|
||||
distance: float = Form(..., description="距离")
|
||||
):
|
||||
# 调用本地 modbus 程序,将距离作为参数传递
|
||||
try:
|
||||
#写入日志精确到毫秒
|
||||
# now = datetime.now()
|
||||
# log_line = f"{now.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]} distance={distance} ts={ts}\n"
|
||||
# with open("/home/orangepi/Opencv/time.txt", "a") as f:
|
||||
# f.write(log_line)
|
||||
result = subprocess.run(
|
||||
[MODBUS_BIN_PATH, str(int(distance))],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return JSONResponse(status_code=500, content={"error": f"modbus程序执行失败: {result.stderr}"})
|
||||
return {
|
||||
"distance": distance,
|
||||
"modbus_output": result.stdout.strip()
|
||||
}
|
||||
except Exception as e:
|
||||
return JSONResponse(status_code=500, content={"error": str(e)})
|
||||
|
||||
|
Reference in New Issue
Block a user