fix
zhangqian
2023-11-06 eaf07953842880673a7a04635661f44a4af0d174
fix
3个文件已修改
6 ■■■■ 已修改文件
constvar/const.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/plc/apacheplc4x/modbusrtu.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/plc/modbusx/connection_manager.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go
@@ -80,7 +80,7 @@
    ParityNull Parity = 3 //无校验
)
func (p Parity) String() string {
func (p Parity) ToString() string {
    switch p {
    case ParityEven:
        return "E"
pkg/plc/apacheplc4x/modbusrtu.go
@@ -15,7 +15,7 @@
func newModbusRTUConnection(c *common.RTUConfig) (plc4go.PlcConnection, error) {
    ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
    // 创建一个新的 PLC 连接
    connectionString := fmt.Sprintf("modbus-rtu:serial://%s?baudrate=%d&databits=%d&stopbits=%d&parity=%s", c.SerialName, c.BaudRate, c.DataBit, c.StopBit, c.Parity)
    connectionString := fmt.Sprintf("modbus-rtu:serial://%s?baudrate=%d&databits=%d&stopbits=%d&parity=%s", c.SerialName, c.BaudRate, c.DataBit, c.StopBit, c.Parity.ToString())
    connectionRequestChanel := driverManager.GetConnection(connectionString)
    // 等待连接响应,同时考虑上下文的超时
    select {
pkg/plc/modbusx/connection_manager.go
@@ -100,7 +100,7 @@
    rtuHandler = modbus.NewRTUClientHandler(c.SerialName)
    rtuHandler.BaudRate = c.BaudRate
    rtuHandler.DataBits = c.DataBit
    rtuHandler.Parity = c.Parity.String()
    rtuHandler.Parity = c.Parity.ToString()
    rtuHandler.StopBits = c.StopBit
    rtuHandler.SlaveId = 1
    rtuHandler.Timeout = 5 * time.Second