Git Product home page Git Product logo

go-modbus's People

Contributors

findgo avatar thinkgos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-modbus's Issues

关于IsConnected连上后断线的处理请教

你好,请问IsConnected()是否会因为连上后对方断线而为false?

p := gomodbus.NewTCPClientProvider("127.0.0.1:1502", gomodbus.WithAutoReconnect(0), gomodbus.WithEnableLogger())
连线上之后对方断线
tcp 127.0.0.1:60127->127.0.0.1:1502: wsasend: An established connection was aborted by the software in your host machine.
自身的IsConnected()仍为true

The port is not being closed

Code:

package main

import (
	"fmt"

	"github.com/goburrow/serial"
	modbus "github.com/things-go/go-modbus"
)

func main() {
	p := modbus.NewRTUClientProvider(modbus.WithEnableLogger(),
	modbus.WithSerialConfig(serial.Config{
		Address:  "\\\\.\\com31",
		BaudRate: 38400,
		DataBits: 8,
		StopBits: 1,
		Parity:   "N",
		Timeout:  modbus.SerialDefaultTimeout,
	}))

	client := modbus.NewClient(p)
	err := client.Connect()
	if err != nil {
		fmt.Println("connect failed, ", err)
		return
	}

	_, err = client.ReadInputRegisters(0x16, 69, 13)
	if err != nil {
		fmt.Println(err.Error())
	}

	fmt.Println("Close err:", client.Close())

	_, err = client.ReadInputRegisters(0x16, 69, 13)
	if err != nil {
		fmt.Println(err.Error())
	}
}

Out:

modbusRTUMaster => 2022/11/21 12:42:20 [D]: sending [16 04 00 45 00 0d 23 3d]
modbusRTUMaster => 2022/11/21 12:42:20 [D]: received [16 04 1a 00 00 00 00 00 01 00 00 80 00 00 03 83 c9 7c e8 20 22 11 15 00 00 80 01 00 05 ea 2d]
Close err: <nil>
modbusRTUMaster => 2022/11/21 12:42:20 [D]: sending [16 04 00 45 00 0d 23 3d]
modbusRTUMaster => 2022/11/21 12:42:20 [D]: received [16 04 1a 00 00 00 00 00 01 00 00 80 00 00 03 83 c9 7c e8 20 22 11 15 00 00 80 01 00 05 ea 2d]

After the client.Close() the port remains open and continues to work

关于采集后的数据处理请教

对于采集到的切片数据进行转换和缩放处理,例如[]byte转换为数据类型int8/16/32/64,uint8/16/32/64,float32/64等(包括多字节数据的大小端处理,高低位转换);以及进行1倍,10倍,0.5倍,-10倍缩放数据。有什么比较好的措施吗?
我自己写了一部分转换,白天发出来请您指点。

Would you like to fix your Example in README?

_, err := client.ReadCoils(1, 0, 10)
		if err != nil {
			fmt.Println(err.Error())
		} else {
			fmt.Printf("ReadCoils % x", results)
		}

should be

results, err = ...

AND

srv.AddNode(modbus.NewNodeRegister(
		1,
		0, 10, []byte{0xfa, 0xa0},
		0, 10, []byte{0xa5, 0x0a},
		0, []uint16{0x1234, 0x4567, 0x1234, 0x4567, 0x1234, 0x4567, 0x4567, 0x1234, 0x4567, 0x1234},
		0, []uint16{0x4567, 0x1234, 0x4567, 0x1234, 0x4567, 0x1234, 0x4567, 0x1234, 0x4567, 0x1234},
	))

should be

modbus.NewNodeRegister(
			1,
			0, 10, 0, 10,
			0, 10, 0, 10),

Of coz, This is a great project ! I like it !

当读取一个slave禁用(diabled)时,timeout后连线数不断上升。

你好,目前测试一种情境:
使用一个client同时读取slave1,2,当其中一个slave被禁用(diabled)后,
会因为读取不到而重新连线,但连线数不断上升。

...
p :=gomodbus.NewTCPClientProvider("127.0.0.1:1502")
for {
time.Sleep(1 * time.Second)
fmt.Println("p.IsConnected()", p.IsConnected()) // is true
client.ReadHoldingRegisters(1, 1, 1)
client.ReadHoldingRegisters(2, 1, 1) // i/o timeout
...
}

使用模拟器ModRSsim2可以观察到连线数不断新增,这边针对timeout的处理是否正常?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.