Skip to content

Instantly share code, notes, and snippets.

@mosluce
Created December 6, 2017 08:12
Show Gist options
  • Save mosluce/28fe133db73fc2d98931832fc50c1d93 to your computer and use it in GitHub Desktop.
Save mosluce/28fe133db73fc2d98931832fc50c1d93 to your computer and use it in GitHub Desktop.
Serial port 列表 (USB、藍芽)...等
package main
import (
"bufio"
"fmt"
"os"
serial "go.bug.st/serial.v1"
)
func main() {
names, err := serial.GetPortsList()
reader := bufio.NewReader(os.Stdin)
if err != nil {
fmt.Printf("發生錯誤 : %s\n", err.Error())
fmt.Println("press ENTER to end")
reader.ReadString('\n')
return
}
fmt.Println("=== USB 裝置清單 ===")
for i := range names {
fmt.Printf("%v. %s\n", i+1, names[i])
}
fmt.Println("press ENTER to end")
reader.ReadString('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment