11package main
22
33import (
4- //"fmt"
5- //"github.com/tarm/goserial"
6- log "github.com/Sirupsen/logrus"
7- "os"
8- "strings"
9- //"encoding/binary"
10- //"strconv"
11- //"syscall"
12- //"fmt"
13- //"bufio"
14- "io/ioutil"
154 "os/exec"
5+ "strings"
166)
177
188// execute system_profiler SPUSBDataType | grep "Vendor ID: 0x2341" -A5 -B2
@@ -32,6 +22,7 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
3222
3323 for index , _ := range ports {
3424 port_hash := strings .Trim (ports [index ].Name , "/dev/tty.usbmodem" )
25+ port_hash = strings .Trim (port_hash , "/dev/tty.usbserial-" )
3526
3627 usbcmd := exec .Command ("system_profiler" , "SPUSBDataType" )
3728 grepcmd := exec .Command ("grep" , "Location ID: 0x" + port_hash [:len (port_hash )- 1 ], "-B6" )
@@ -65,48 +56,3 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
6556 }
6657 return ports
6758}
68-
69- func getList () ([]OsSerialPort , os.SyscallError ) {
70- //return getListViaWmiPnpEntity()
71- return getListViaTtyList ()
72- }
73-
74- func getListViaTtyList () ([]OsSerialPort , os.SyscallError ) {
75- var err os.SyscallError
76-
77- log .Println ("getting serial list on darwin" )
78-
79- // make buffer of 100 max serial ports
80- // return a slice
81- list := make ([]OsSerialPort , 100 )
82-
83- files , _ := ioutil .ReadDir ("/dev/" )
84- ctr := 0
85- for _ , f := range files {
86- if strings .HasPrefix (f .Name (), "tty." ) {
87- // it is a legitimate serial port
88- list [ctr ].Name = "/dev/" + f .Name ()
89- list [ctr ].FriendlyName = f .Name ()
90- log .Println ("Added serial port to list: " , list [ctr ])
91- ctr ++
92- }
93- // stop-gap in case going beyond 100 (which should never happen)
94- // i mean, really, who has more than 100 serial ports?
95- if ctr > 99 {
96- ctr = 99
97- }
98- //fmt.Println(f.Name())
99- //fmt.Println(f.)
100- }
101- /*
102- list := make([]OsSerialPort, 3)
103- list[0].Name = "tty.serial1"
104- list[0].FriendlyName = "tty.serial1"
105- list[1].Name = "tty.serial2"
106- list[1].FriendlyName = "tty.serial2"
107- list[2].Name = "tty.Bluetooth-Modem"
108- list[2].FriendlyName = "tty.Bluetooth-Modem"
109- */
110-
111- return list [0 :ctr ], err
112- }
0 commit comments