Example #1
0
// connect to either a net port for telnet use, or to a serial device
func connect(name string) (io.ReadWriter, error) {
	if isNetPort(name) {
		return net.Dial("tcp", name)
	}

	config := serial.Config{Name: *port, Baud: *baud}
	if *upload != "" {
		config.Parity = serial.ParityEven
	}
	return serial.OpenPort(&config)
}
Example #2
0
func changeGPSBaudRate(config *serial.Config, newRate int) error {
	if config.Baud == newRate {
		return nil
	}

	p, err := serial.OpenPort(config)
	if err != nil {
		return err
	}
	defer p.Close()

	baud_cfg := createChecksummedNMEASentence([]byte(fmt.Sprintf("PMTK251,%d", newRate)))

	_, err = p.Write(baud_cfg)
	if err != nil {
		return err
	}

	config.Baud = newRate

	valid, err := detectGPS(config)
	if !valid {
		err = fmt.Errorf("Set GPS to new rate, but unable to detect it at that new rate!")
	}
	return err
}