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

serial read only returns one byte #6

Open
cbrake opened this issue Apr 20, 2020 · 1 comment
Open

serial read only returns one byte #6

cbrake opened this issue Apr 20, 2020 · 1 comment

Comments

@cbrake
Copy link

cbrake commented Apr 20, 2020

I have created a simple server and client apps:

https://github.com/simpleiot/simpleiot/blob/feature-modbus/cmd/modbus-client/main.go

https://github.com/simpleiot/simpleiot/blob/feature-modbus/cmd/modbus-server/main.go

When I send a packet to the server, it only ever receives one byte.

What causes the the Read() at this location:

https://github.com/tbrandon/mbserver/blob/master/servertu.go#L26

func (s *Server) acceptSerialRequests(port serial.Port) {
	for {
		buffer := make([]byte, 512)

		bytesRead, err := port.Read(buffer)
		if err != nil {
			if err != io.EOF {
				log.Printf("serial read error %v\n", err)
			}
			return
		}

		if bytesRead != 0 {

			// Set the length of the packet to the number of read bytes.
			packet := buffer[:bytesRead]

			frame, err := NewRTUFrame(packet)
			if err != nil {
				log.Printf("bad serial frame error %v\n", err)
				return
			}

			request := &Request{port, frame}

			s.requestChan <- request
		}
	}
}

To read an entire packet, instead of just several bytes?

Thanks,
Cliff

@cbrake
Copy link
Author

cbrake commented Apr 28, 2020

closing this as this project appears to not be maintained. I started a new modbus library that will implement both client and server functionality:

https://github.com/simpleiot/simpleiot/tree/master/modbus

Examples:

https://github.com/simpleiot/simpleiot/blob/master/modbus/rtu-end-to-end_test.go
https://github.com/simpleiot/simpleiot/blob/master/cmd/modbus-client/main.go
https://github.com/simpleiot/simpleiot/blob/master/cmd/modbus-server/main.go

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

1 participant