Exemplo n.º 1
0
func NewOBD(serialPortName string) (*OBD, error) {
	port, err := term.Open(serialPortName, term.Speed(9600), term.RawMode)
	if err != nil {
		return nil, err
	}
	obd := &OBD{port, true}
	err = obd.Reset()
	if err != nil {
		return nil, err
	}
	err = obd.SendCommand([]byte("ate0")) // Turns off echo
	obd.ReadResult()
	return obd, err
}
Exemplo n.º 2
0
func main() {
	var baud int
	var dev string

	cmd := &cobra.Command{
		Use:   "junkterm",
		Short: "junkterm is a quick and dirty serial terminal.",
		Run: func(cmd *cobra.Command, args []string) {
			term, err := term.Open(dev, term.Speed(baud), term.RawMode)
			if err != nil {
				log.Fatal(err)
			}
			go io.Copy(os.Stdout, term)
			io.Copy(term, os.Stdin)
		},
	}

	cmd.Flags().IntVarP(&baud, "baud", "b", 115200, "baud rate")
	cmd.Flags().StringVarP(&dev, "dev", "d", "/dev/USB0", "device")

	cmd.Execute()
}