Documentation ¶
Overview ¶
Package discovery keeps an updated list of the devices connected to the computer, via serial ports or found in the network
Usage:
monitor := discovery.New(time.Millisecond) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) monitor.Start(ctx) time.Sleep(10 * time.Second) fmt.Println(monitor.Serial()) fmt.Println(monitor.Network())
Output:
map[/dev/ttyACM0:0x2341/0x8036] map[192.168.1.107:YunShield]
You may also decide to subscribe to the Events channel of the Monitor:
monitor := discovery.New(time.Millisecond) ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) monitor.Start(ctx) for ev := range monitor.Events { fmt.Println(ev) }
Output:
{add 0x2341/0x8036 <nil>} {add <nil> YunShield}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { Name string `json:"name"` SerialDevice *SerialDevice `json:"serial_device,omitempty"` NetworkDevice *NetworkDevice `json:"network_device,omitempty"` }
Event tells you that something has changed in the list of connected devices. Name can be one of ["Add", "Change", "Remove"] SerialDevice or NetworkDevice can be present and they refer to the device that has been added, changed, or removed
type Monitor ¶
Monitor periodically checks the serial ports and the network in order to have an updated list of Serial and Network ports.
You can subscribe to the Events channel to get realtime notification of what's changed
func New ¶
New Creates a new monitor that can start querying the serial ports and the local network for devices
func (Monitor) MarshalJSON ¶
MarshalJSON allows a monitor to be parsed as a JSON object.
func (*Monitor) Network ¶
func (m *Monitor) Network() NetworkDevices
Network returns a cached list of devices found on the local network
func (*Monitor) Serial ¶
func (m *Monitor) Serial() SerialDevices
Serial returns a cached list of devices connected to the serial ports
func (*Monitor) Start ¶
func (m *Monitor) Start()
Start begins the loop that queries the serial ports and the local network.
type NetworkDevice ¶
type NetworkDevice struct { Address string `json:"address"` Info string `json:"info"` Name string `json:"name"` Port int `json:"port"` }
NetworkDevice is something connected to the Network Ports
func (NetworkDevice) String ¶
func (d NetworkDevice) String() string
type NetworkDevices ¶
type NetworkDevices map[string]*NetworkDevice
NetworkDevices is a list of currently connected devices to the computer
func (NetworkDevices) MarshalJSON ¶
func (nds NetworkDevices) MarshalJSON() ([]byte, error)
MarshalJSON allows to convert this object to a JSON string.
func (NetworkDevices) String ¶
func (nds NetworkDevices) String() string
type SerialDevice ¶
type SerialDevice struct { Port string `json:"port"` SerialNumber string `json:"serial_number"` ProductID string `json:"pid"` VendorID string `json:"vid"` }
SerialDevice is something connected to the Serial Ports
func (SerialDevice) String ¶
func (d SerialDevice) String() string
type SerialDevices ¶
type SerialDevices map[string]*SerialDevice
SerialDevices is a list of currently connected devices to the computer
func (SerialDevices) MarshalJSON ¶
func (sds SerialDevices) MarshalJSON() ([]byte, error)
MarshalJSON allows to convert this object to a JSON string.
func (SerialDevices) String ¶
func (sds SerialDevices) String() string