commit 2021-12-16]11:54:54

This commit is contained in:
Godopu 2021-12-16 11:54:57 +09:00
parent ab08e7ab15
commit 37705d6fe5
2 changed files with 11 additions and 12 deletions

13
cli.go
View File

@ -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)

View File

@ -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 {