tarm / serial

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

Always returns [65] #70

Closed 5k3105 closed 6 years ago

5k3105 commented 6 years ago

on windows 7. Using Termite: Port: COM1 Baud rate: 115200 Data bits: 8 Stop bits: 1 Parity: none Flow control: none

TEMPS?
AC/DC Temperature 1 = 56 C
AC/DC Temperature 2 = 51 C
Control Brd Temp = 39 C
DC/AC Temperature = 39 C
DC2 Temperature = 55.18 C
DC2 Temperature 2 = 51.18 C
Battery Temperature = 29.8 C

Code below gives [65] though:

λ telem_serial.exe
2017/10/24 23:47:58 %q[65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
buf len:  1
package main

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

func main() {
    c := &serial.Config{Name: "COM1", Baud: 115200}
    s, err := serial.OpenPort(c)
    if err != nil {
        log.Fatal(err)
    }

    err = s.Flush()
    if err != nil {
        log.Fatal(err)
    }

    cmd := []byte("TEMPS?\r\n")
    n, err := s.Write(cmd)
    if err != nil {
        log.Fatal(err)
    }

    buf := make([]byte, 128)
    n, err = s.Read(buf)
    if err != nil {
        log.Fatal(err)
    }
    log.Print("%q", buf) //buf[:n])
    println("buf len: ", n)
}
5k3105 commented 6 years ago

Actually, if I send it a different command, it gives me the first letter of the response. So it is returning correct data, just only one byte of it.

Any ideas?

5k3105 commented 6 years ago

Got same issue using github.com/knieriem/serport however, https://github.com/jacobsa/go-serial worked correctly.