Created
April 27, 2020 12:15
-
-
Save sago35/44c11bf100edee171f5c52647b9b215b to your computer and use it in GitHub Desktop.
touchSerialPortAt1200bps
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 ( | |
"fmt" | |
"log" | |
"time" | |
"go.bug.st/serial" | |
) | |
func main() { | |
err := touchSerialPortAt1200bps(`COM7`) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func touchSerialPortAt1200bps(port string) (err error) { | |
retryCount := 3 | |
for i := 0; i < retryCount; i++ { | |
// Open port | |
p, e := serial.Open(port, &serial.Mode{BaudRate: 1200}) | |
if e != nil { | |
time.Sleep(1 * time.Second) | |
err = e | |
continue | |
} | |
defer p.Close() | |
p.SetDTR(false) | |
return nil | |
} | |
return fmt.Errorf("opening port: %s", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment