Skip to content

coreyog/board-discovery

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Board Discovery (Golang)

This package allows to discover and monitor Arduino boards connected to the network or the serial ports.

Getting the package

$ go get github.com/arduino/board-discovery

Then import it to use it:

import "github.com/arduino/board-discovery"
GODOC can be found HERE

Discovering devices

To discover devices you must first create a new Monitor (specifying the polling interval):

monitor := discovery.New(time.Millisecond)

Then start, get data and stop it when you don’t need it anymore:

monitor.Start()
//Get devices connected
monitor.Stop()

You can get connected devices (via Serial or Network ports) by using the following functions:

serialDevices := monitor.Serial()
networkDevices := monitor.Network()

The Monitor

Monitor periodically (period specified by Interval) 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.

type Monitor struct {
	Interval time.Duration
	Events   chan Event
}

You can Start, Stop and Restart a Monitor, using the specified functions.

monitor.Start() // Starts monitoring
monitor.Stop()  // Stops monitoring
monitor.Restart // Restarts the monitor (Stop, then Start)

To have the list of devices discovered, you can use (assuming a started monitor m):

  1. m.Serial() to get the list of devices connected via serial interface.

  2. m.Network() to get the list of devices connected via the network.

The device types

SerialDevice represents a device connected via serial port:

type SerialDevice struct {
	Port         string
	SerialNumber string
	ProductID    string
	VendorID     string
	Serial       *serial.Info
}

type SerialDevices map[string]*SerialDevice

NetworkDevice represents a device connected via the network:

type NetworkDevice struct {
	Address string
	Info    string
	Name    string
	Port    int
}

type NetworkDevices map[string]*NetworkDevice

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%