gobot.io/x/gobot/v2@v2.1.0/platforms/firmata/tcp_firmata_adaptor.go (about)

     1  package firmata
     2  
     3  import (
     4  	"io"
     5  	"net"
     6  
     7  	"gobot.io/x/gobot/v2"
     8  )
     9  
    10  // TCPAdaptor represents a TCP based connection to a microcontroller running
    11  // WiFiFirmata
    12  type TCPAdaptor struct {
    13  	*Adaptor
    14  }
    15  
    16  func connect(address string) (io.ReadWriteCloser, error) {
    17  	return net.Dial("tcp", address)
    18  }
    19  
    20  // NewTCPAdaptor opens and uses a TCP connection to a microcontroller running
    21  // WiFiFirmata
    22  func NewTCPAdaptor(args ...interface{}) *TCPAdaptor {
    23  	address := args[0].(string)
    24  
    25  	a := NewAdaptor(address)
    26  	a.SetName(gobot.DefaultName("TCPFirmata"))
    27  	a.PortOpener = func(port string) (io.ReadWriteCloser, error) {
    28  		return connect(port)
    29  	}
    30  
    31  	return &TCPAdaptor{
    32  		Adaptor: a,
    33  	}
    34  }