tarm / serial

BSD 3-Clause "New" or "Revised" License
1.6k stars 451 forks source link

Unable to read AT command response on windows 10 machine using 8 Port USB Modem Pool #114

Open mateors opened 4 years ago

mateors commented 4 years ago

I am using windows 10 operating system and send AT+COPS? command to my USB modem pool device connected to my machine. It seems AT command is sending and working properly but still response receive empty.

seemy code and command output

c := &serial.Config{Name: "COM7", Baud: 115200, Parity: 'N', StopBits: 1, ReadTimeout: time.Second * 3}

port, err := serial.OpenPort(c)
if err != nil {
    fmt.Println("OpenError: ", err)
}
defer port.Close()

n, err := port.Write([]byte("AT+COPS?\n"))
if err != nil {
    fmt.Println("ERROR: ", err)
}
time.Sleep(1 * time.Second)

buffer := make([]byte, 1024)
n, err = port.Read(buffer)
if err != nil {
    fmt.Println("ERROR: ", err)
}
fmt.Printf("DATA: %v %d", buffer[:n], n)

Output:
DATA: [] 0

same device working perfectly with my c# code.

is there anything missing from my side? or its a bug?

LauJangit commented 3 years ago

same problem in win 10 with single port modem

peteArnt commented 1 year ago

I may be a little late to the party, but here goes: Instead of using "\n" as a terminator for your AT command, try using "\r". The newline may be ignored by the modem.