forked from bugst/go-serial
-
Notifications
You must be signed in to change notification settings - Fork 3
/
portlist.go
37 lines (34 loc) · 885 Bytes
/
portlist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// portlist is a tool to list all the available serial ports.
// Just run it and it will produce an output like:
//
// $ go run portlist.go
// Port: /dev/cu.Bluetooth-Incoming-Port
// Port: /dev/cu.usbmodemFD121
// USB ID 2341:8053
// USB serial FB7B6060504B5952302E314AFF08191A
//
package main
import "fmt"
import "log"
import "go.bug.st/serial/enumerator"
func main() {
ports, err := enumerator.GetDetailedPortsList()
if err != nil {
log.Fatal(err)
}
if len(ports) == 0 {
return
}
for _, port := range ports {
fmt.Printf("Port: %s\n", port.Name)
if port.IsUSB {
fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID)
fmt.Printf(" USB serial %s\n", port.SerialNumber)
}
}
}