1 Star 0 Fork 1

flyiot/flylibs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FlyModbusSlaveSettings.go 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
flyrainning 提交于 2023-07-09 03:12 +08:00 . u
package FlyModbusSlaves
import (
"errors"
"gitee.com/flyiot/flylibs/FlyConfigFile"
)
type FlyModbusSlaveSettings struct {
Enable bool
ConfigType string
ConfigKey string
Debug bool
SlaveID uint
EnableTcp bool
EnableSerial bool
MirrorAddress int
TcpAddr string
Port string
BaudRate uint
DataBits uint
ParityMode string
StopBits uint
MinimumReadSize uint
InterCharacterTimeout uint
Ready bool
}
func NewFlyModbusSlaveSettings() *FlyModbusSlaveSettings {
s := FlyModbusSlaveSettings{}
s.SlaveID = 1
s.TcpAddr = "0.0.0.0:1502"
s.BaudRate = 115200
s.DataBits = 8
s.ParityMode = "none"
s.StopBits = 1
s.MinimumReadSize = 1
s.InterCharacterTimeout = 0
s.MirrorAddress = 40000
return &s
}
// 从ini加载配置信息
func (s *FlyModbusSlaveSettings) LoadIni(config *FlyConfigFile.FlyIni, key string) error {
s.Ready = false
if !config.Ready {
return errors.New("config file error")
}
s.Enable = config.GetBool(key, "enable", true)
s.ConfigType = "ini"
s.ConfigKey = key
s.Debug = config.GetBool(key, "debug", false)
s.SlaveID = config.GetUint(key, "slave_id", 1)
s.EnableTcp = config.GetBool(key, "enable_tcp", true)
s.EnableSerial = config.GetBool(key, "enable_serial", true)
s.TcpAddr = config.GetString(key, "tcp_addr", "0.0.0.0:1502")
s.Port = config.GetString(key, "port", "")
s.BaudRate = config.GetUint(key, "baudrate", 115200)
s.DataBits = config.GetUint(key, "databits", 8)
s.ParityMode = config.GetString(key, "paritymode", "none")
s.StopBits = config.GetUint(key, "stopbits", 1)
s.MinimumReadSize = config.GetUint(key, "minimumreadsize", 1)
s.InterCharacterTimeout = config.GetUint(key, "intercharactertimeout", 0)
s.MirrorAddress = config.GetInt(key, "mirror_address", 40000)
s.Ready = true
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/flyiot/flylibs.git
git@gitee.com:flyiot/flylibs.git
flyiot
flylibs
flylibs
b9c81f1c9857

搜索帮助