From e6c81b3916494ef51edc21774a27402d0f16c49c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 24 八月 2023 17:21:04 +0800 Subject: [PATCH] plc配置支持serial和modbusTCP两种方式 --- api/v1/config.go | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/api/v1/config.go b/api/v1/config.go index 4cf65b0..4765bcf 100644 --- a/api/v1/config.go +++ b/api/v1/config.go @@ -2,6 +2,7 @@ import ( "apsClient/conf" + "apsClient/constvar" "apsClient/model" "apsClient/model/request" _ "apsClient/model/response" @@ -119,6 +120,20 @@ return } + if !params.Method.Valid() { + ctx.FailWithMsg(ecode.ParamsErr, "鎺ュ彛鏂瑰紡涓嶆纭�") + return + } + + if params.Method == constvar.PlcMethodModbusTCP && (params.Address == "" || params.Port == 0) { + ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负modbusTCP鏃讹紝address鍜宲ort涓嶈兘涓虹┖") + return + } + if params.Method == constvar.PlcMethodSerial && (params.BaudRate == 0 || params.SerialName == "") { + ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负serial鏃讹紝baudRate鍜宻erialName涓嶈兘涓虹┖") + return + } + errCode := service.NewDevicePlcService().UpdateDevicePlc(¶ms) if errCode != ecode.OK { ctx.Fail(errCode) -- Gitblit v1.8.0