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

When receiving data, one segment of data is divided into two segments #83

Closed
elegantm opened this issue May 31, 2018 · 4 comments
Closed

Comments

@elegantm
Copy link

Main Environment
OS: win10 x64
GO env: GOARCH=amd64
`
package main

import (
"fmt"
"github.com/tarm/serial"
"log"
)

func main() {

fmt.Printf("lanuch server \n")

c := &serial.Config{
	Name: "COM3",
	Baud: 115200,
	//ReadTimeout:time.Second *5,
}

s, err := serial.OpenPort(c)
if err != nil {
	log.Fatal(err)
}
buf := make([]byte, 128)
for{
		n, err := s.Read(buf)
		if err != nil {
		log.Fatal(err)

}
	fmt.Printf("%q", buf[:n])

}
}
`
image

When I send "123456 ", data is divided into two segments
part A: "1"
partB : "23456"

@paocalvi
Copy link

paocalvi commented May 31, 2018 via email

@elegantm
Copy link
Author

elegantm commented Jun 1, 2018

sorry,may the serial tool bug . Virtual Serial Port Driver not exactly baudrate emulation.
I test serial port with baudrate emulation.
test A: disable baudrate
disable baudrate
test B: enable baudrate
enable baudrate

one segment of data is divided into many segments
@paocalvi

@tarm
Copy link
Owner

tarm commented Jun 1, 2018

With serial communication there is no "packet" like there is on Ethernet, UDP, etc. Some protocols may use a particular character as a delimiter (like '\n') but other protocols just send bytes. The serial library does not make any assumptions about the delimiter so that it can be used in different contexts.

In addition, serial is very slow by modern standards. At 115200, it might take ~1ms for 10 characters to arrive. Instead of waiting for a delimiter or waiting for a timeout before returning the buffered bytes, the serial library will immediately return as soon as there are any bytes in the buffer (even the first byte), but will block if there are no bytes waiting. With the provided serial API, you can build support for many different protocols in an efficient manner whether the protocols are newline delimited or have some other structure.

@elegantm
Copy link
Author

elegantm commented Jun 1, 2018

@tarm @paocalvi thank you . Thank you for your guidance

@elegantm elegantm closed this as completed Jun 1, 2018
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