Created
December 2, 2018 22:28
-
-
Save selfup/ca9522a4719b20c608a99a8a6b526519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/hex" | |
"log" | |
"strconv" | |
"strings" | |
"github.com/jacobsa/go-serial/serial" | |
) | |
func main() { | |
// ZZ starts all commands | |
// ; terminates all commands | |
// Z == 7A | |
// M = 6D | |
// D == 64 | |
// ; == 3B | |
// 7A7A6D643B | |
// ask if radio is in USB mode | |
// should respond with 1 if in USB mode and 0 if not | |
icomCmds := strings.Split("7A7A6D643B", " ") | |
byteCmd := strings.Join(icomCmds, "") | |
baudInt, err := strconv.ParseInt("9600", 10, 32) | |
if err != nil { | |
panic(err) | |
} | |
data, err := hex.DecodeString(byteCmd) | |
if err != nil { | |
panic(err) | |
} | |
options := serial.OpenOptions{ | |
PortName: "COM4", | |
BaudRate: uint(baudInt), | |
DataBits: 8, | |
StopBits: 1, | |
MinimumReadSize: 4, | |
} | |
port, err := serial.Open(options) | |
if err != nil { | |
log.Fatalf("serial.Open: %v", err) | |
} | |
defer port.Close() | |
_, err = port.Write(data) | |
if err != nil { | |
log.Fatalf("port.Write: %v", err) | |
} | |
readBuf := make([]byte, 1000) | |
if c, err := port.Read(readBuf); err != nil { | |
log.Panic(err) | |
} else { | |
log.Println(string(readBuf)) | |
log.Print(c) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment