From 72721bf221e6f90fb830bf28133c7588e30e1d30 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 26 十月 2023 17:41:19 +0800
Subject: [PATCH] fix

---
 service/device_plc.go |    5 ++++-
 api/v1/config.go      |   10 ++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/api/v1/config.go b/api/v1/config.go
index 267a041..08642f8 100644
--- a/api/v1/config.go
+++ b/api/v1/config.go
@@ -125,12 +125,18 @@
 		return
 	}
 
+	params.DeviceID = conf.Conf.System.DeviceId
 	if params.Method == constvar.PlcMethodModbusTCP && (params.Address == "" || params.Port == 0) {
-		ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负modbusTCP鏃讹紝address鍜宲ort涓嶈兘涓虹┖")
+		ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负modbusTCP鏃讹紝鍦板潃鍜岀鍙e彿涓嶈兘涓虹┖")
 		return
 	}
 	if params.Method == constvar.PlcMethodSerial && (params.BaudRate == 0 || params.SerialName == "") {
-		ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负serial鏃讹紝baudRate鍜宻erialName涓嶈兘涓虹┖")
+		ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负serial鏃讹紝娉㈢壒鐜囧拰涓插彛鍚嶇О涓嶈兘涓虹┖")
+		return
+	}
+
+	if params.Method == constvar.PlcMethodModbusRTU && (params.DataBit == 0 || params.StopBit == 0 || params.Parity == 0) {
+		ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负modbusRTU鏃讹紝鏁版嵁浣嶏紝鍋滄浣嶏紝鏍¢獙浣嶄笉鑳戒负绌�")
 		return
 	}
 
diff --git a/service/device_plc.go b/service/device_plc.go
index fc5fadc..c4f46a1 100644
--- a/service/device_plc.go
+++ b/service/device_plc.go
@@ -22,14 +22,17 @@
 	DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.System.DeviceId).First()
 	if err == gorm.ErrRecordNotFound {
 		return &model.DevicePlc{
+			DeviceID:   "",
 			Brand:      "",
 			Method:     "",
 			Address:    "",
 			Port:       0,
 			BaudRate:   0,
 			SerialName: "",
+			DataBit:    0,
+			StopBit:    0,
+			Parity:     0,
 			IsOpen:     false,
-			Detail:     "",
 			Details:    make([]*model.DevicePlcAddress, 0),
 		}, ecode.OK
 	}

--
Gitblit v1.8.0