commit 2021-12-16]11:54:54
This commit is contained in:
parent
ab08e7ab15
commit
37705d6fe5
13
cli.go
13
cli.go
@ -65,14 +65,13 @@ func AddRecvListener(h EventHandler) {
|
||||
// }
|
||||
|
||||
func Run() error {
|
||||
iface, err := puserial.InitDevice()
|
||||
ifaces, err := puserial.InitDevice()
|
||||
if err != nil {
|
||||
if err.Error() != "USB Not found" {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// _managerObj.onAdd(iface)
|
||||
_managerObj.onAdded(iface)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, e := range ifaces {
|
||||
_managerObj.onAdded(e)
|
||||
}
|
||||
|
||||
go puserial.WatchNewDevice(ctx, ch_discover)
|
||||
|
@ -2,7 +2,6 @@ package puserial
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
@ -11,19 +10,20 @@ import (
|
||||
"github.com/rjeczalik/notify"
|
||||
)
|
||||
|
||||
func InitDevice() (string, error) {
|
||||
func InitDevice() ([]string, error) {
|
||||
fs, err := ioutil.ReadDir("/dev")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []string = nil
|
||||
for _, f := range fs {
|
||||
if strings.Contains(f.Name(), "ttyACM") {
|
||||
return filepath.Join("/dev", f.Name()), nil
|
||||
result = append(result, filepath.Join("/dev", f.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("USB Not found")
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func WatchNewDevice(ctx context.Context, ch_discover chan<- notify.EventInfo) error {
|
||||
|
Loading…
Reference in New Issue
Block a user