Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTU server unstable #13

Open
NV4RE opened this issue Mar 10, 2022 · 2 comments
Open

RTU server unstable #13

NV4RE opened this issue Mar 10, 2022 · 2 comments

Comments

@NV4RE
Copy link

NV4RE commented Mar 10, 2022

Most of the time serial did not read all the data frame and return error "bad serial frame error %v\n"

bytesRead, err := port.Read(buffer)

Because it don't know when to start/stop reading

@LeeGaning
Copy link

you should set a timeout when open the port

		err = serv.ListenRTU(&serial.Config{
			Address:  addr,
			BaudRate: cfg.Rtu.BaudRate,
			DataBits: 8,
			StopBits: 1,
			Parity:   cfg.Rtu.Parity,
			Timeout:  time.Duration(cfg.Rtu.Timeout) * time.Millisecond})

@nuannuande
Copy link

in serverrtu.go , you can append multiple buffer to one buffer then exec NewRTUFrame()

if bytesRead != 0 {
		// Set the length of the packet to the number of read bytes.
		packet := buffer[:bytesRead]
		res1 := append(Abuf, packet...)
		if len(Abuf) > 20 {
			CleanAbuf()
		}
		frame, err := NewRTUFrame(res1)
		if err != nil {
			Abuf = res1
			continue SkipFrameError
			//return
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants