From 620d904921c76b6b29d1b69787da7a82121d4c31 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 26 十月 2023 21:15:35 +0800
Subject: [PATCH] 读写plc支持modbusRTU

---
 model/device_plc.go |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/model/device_plc.go b/model/device_plc.go
index 2a2ccaa..c68b1f3 100644
--- a/model/device_plc.go
+++ b/model/device_plc.go
@@ -13,15 +13,20 @@
 	// DevicePlc 璁惧鐨凱LC閰嶇疆
 	DevicePlc struct {
 		gorm.Model
-		DeviceID   string             `gorm:"column:device_id;type:varchar(255);not null;unique_index" json:"deviceID"` //璁惧缂栧彿
+		DeviceID   string             `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //璁惧缂栧彿
 		Brand      string             `gorm:"type:varchar(191)" json:"brand"`
 		Method     constvar.PlcMethod `gorm:"type:varchar(191)" json:"method"`
 		Address    string             `gorm:"type:varchar(191)" json:"address"` //plc ip鍦板潃锛� method = modbusTCP鐢�
 		Port       int                `json:"port"`                             //plc 绔彛鍙凤紝  method =  modbusTCP鐢�
 		BaudRate   int                `json:"baudRate"`                         //涓插彛娉㈢壒鐜囷紝 method = serial鏃� 鐢�
 		SerialName string             `json:"serialName"`                       //涓插彛鍚嶇О锛宮ethod = serial鏃� 鐢�
-		IsOpen     bool               `json:"isOpen"`
-		Detail     string             `gorm:"type:varchar(2048)" json:"-"`
+
+		DataBit int             `gorm:"type:int(11)"  json:"dataBit"` //鏁版嵁浣嶏紝method = modbusRTU 鐢�
+		StopBit int             `gorm:"type:int(11)"  json:"stopBit"` //鍋滄浣嶏紝method = modbusRTU 鐢�
+		Parity  constvar.Parity `gorm:"type:int(11)"  json:"parity"`  //鏍¢獙鏂瑰紡锛宮ethod = modbusRTU 鐢�
+
+		IsOpen bool   `json:"isOpen"`
+		Detail string `gorm:"type:varchar(2048)" json:"-"`
 
 		Details []*DevicePlcAddress `gorm:"-" json:"details"`
 
@@ -122,7 +127,7 @@
 func (slf *DevicePlcSearch) Save(record *DevicePlc) error {
 	var db = slf.build()
 
-	if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
+	if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
 		return fmt.Errorf("save err: %v, record: %+v", err, record)
 	}
 

--
Gitblit v1.8.0