This commit is contained in:
Andrey Egorov 2024-07-22 20:24:30 +03:00
parent 14e2a2329e
commit aa6f1b45d1

View File

@ -87,24 +87,27 @@ func (p *atPort) Disconnect() error {
func (p *atPort) makeReq(msg string) (string, error) {
// Write
p.port.ResetInputBuffer()
log.Println("Write...") // DEBUG
if written, err := p.port.Write([]byte(msg)); err != nil {
if _, err := p.port.Write([]byte(msg)); err != nil {
return "", fmt.Errorf("serial port write: %w", err)
} else {
log.Println("Written:", written) // DEBUG
}
// Read
log.Println("Read...") // DEBUG
readLen, err := p.port.Read(p.inputBuf)
if err != nil {
return "", fmt.Errorf("port read: %w", err)
}
log.Println("Read: ", readLen, string(p.inputBuf[:readLen])) // DEBUG
return string(p.inputBuf[:readLen]), nil
}
func (p *atPort) Request(cmdType CmdType, cmd string) (string, error) {
func (p *atPort) Request(cmdType CmdType, cmd string) (outStr string, outErr error) {
defer func() {
if outErr != nil {
return
}
log.Println("GOT:", outStr, "BYTE:", []byte(outStr))
}()
msg := "AT"
// Make command
// By default it just will be AT check cmd