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