model/common/common.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
model/device_plc.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
nsq/msg_handler.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
model/common/common.go
@@ -1,6 +1,9 @@ package common import "github.com/shopspring/decimal" import ( "apsClient/constvar" "github.com/shopspring/decimal" ) // 排程任务下发 type ( @@ -65,6 +68,29 @@ KeyData []byte AddressData []byte DeviceId string PlcAddressList []*PlcAddress PlcConfig PlcConfig } PlcConfig struct { Brand string `gorm:"type:varchar(191);comment:PLC品牌" json:"brand"` Method constvar.PlcMethod `gorm:"type:varchar(191);comment:接口方式" json:"method"` Address string `gorm:"type:varchar(191);comment:PLC地址" json:"address"` //plc ip地址, method = modbusTCP用 Port int `gorm:"type:int(11);comment:端口" json:"port"` //plc 端口号, method = modbusTCP用 BaudRate int `gorm:"type:int(11);comment:波特率" json:"baudRate"` //串口波特率, method = serial时 用 SerialName string `gorm:"type:int(11);comment:串口名称" json:"serialName"` //串口名称,method = serial时 用 IsOpen bool `gorm:"type:tinyint(1);comment:是否开启" json:"isOpen"` Detail string `gorm:"type:varchar(2048);comment:数据详情" json:"-"` Details []*PlcAddress `gorm:"-" json:"details"` } PlcAddress struct { DeviceID string `json:"deviceID"` // 设备id Position int `json:"position"` // 生产位置,一个机器可能有多个机位,需要分别配置plc地址 StartAddress int `json:"startAddress"` // 数据起始地址 Length int `json:"length"` // 数据长度 Type string `json:"type"` // 数据类型 FieldName constvar.PlcStartAddressType `json:"fieldName"` // 对应系统字段,完成量或总量 } ) model/device_plc.go
@@ -33,6 +33,7 @@ } DevicePlcAddress struct { Position int `json:"position"` // 数据起始地址 StartAddress int `json:"startAddress"` // 数据起始地址 Length int `json:"length"` // 数据长度 Type constvar.PlcStartAddressValueType `json:"type"` // 数据类型 nsq/msg_handler.go
@@ -11,6 +11,7 @@ "apsClient/utils/file" "encoding/json" "fmt" "github.com/mitchellh/mapstructure" "github.com/spf13/cast" "gorm.io/gorm" "strings" @@ -123,9 +124,7 @@ Topic: slf.Topic, Message: data, } if len(resp.KeyData) == 0 || len(resp.AddressData) == 0 { return nil } if len(resp.KeyData) != 0 && len(resp.AddressData) != 0 { //写入到文件 err = file.WriteFile(fmt.Sprintf("%s%s", constvar.PlcAddressDataPath, constvar.PlcAddressDataKeyFileName), resp.KeyData) if err != nil { @@ -151,6 +150,24 @@ plc_address.Set(key, address) logx.Infof("plc address set ok: key:%v, address:%v", key, address) } } var record model.DevicePlc err = mapstructure.Decode(resp.PlcConfig, &record) if err != nil { logx.Infof("decode from PlcAddressList to DevicePlc Details err:%v", err) } err = mapstructure.Decode(resp.PlcAddressList, &record.Details) if err != nil { logx.Infof("decode from PlcAddressList to DevicePlc Details err:%v", err) } detail, err := json.Marshal(record.Details) record.Detail = string(detail) record.Id = 1 err = model.NewDevicePlcSearch().SetId(record.Id).Save(&record) if err != nil { return err } return nil }