I use vspd create COM1 and COM2 on Win10,
S -> like this:
func main() {
s, err := serial.Open(&serial.Config{
Address: "COM1",
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
Parity: "N",
})
if err != nil {
log.Fatal(err)
}
//
defer s.Close()
buf := make([]byte, 128)
log.Println("begin")
n, err := s.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Println("end")
log.Println(string(buf[:n]))
}
C-> like this:
func main() {
s, err := serial.Open(&serial.Config{
Address: "COM2",
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
Parity: "N",
})
if err != nil {
log.Fatal(err)
}
//
n, err := s.Write([]byte("123"))
if err != nil {
log.Fatal(err)
}
//
log.Printf("write: %d\n", n)
//
defer s.Close()
buf := make([]byte, 128)
time.Sleep(1000 * time.Millisecond)
n, err = s.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Println(string(buf[:n]))
}
first I run S then C I found S read nothing, I don't no why? can you help me?