2017-01-03 03:00:16 +08:00
|
|
|
package firmata
|
|
|
|
|
2017-01-15 20:51:07 +08:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
)
|
2017-01-03 03:00:16 +08:00
|
|
|
|
|
|
|
// TCPAdaptor represents a TCP based connection to a microcontroller running
|
|
|
|
// WiFiFirmata
|
|
|
|
type TCPAdaptor struct {
|
|
|
|
*Adaptor
|
|
|
|
}
|
|
|
|
|
2017-01-15 20:51:07 +08:00
|
|
|
func connect(address string) (io.ReadWriteCloser, error) {
|
|
|
|
return net.Dial("tcp", address)
|
|
|
|
}
|
|
|
|
|
2017-01-03 03:00:16 +08:00
|
|
|
// NewTCPAdaptor opens and uses a TCP connection to a microcontroller running
|
|
|
|
// WiFiFirmata
|
|
|
|
func NewTCPAdaptor(args ...interface{}) *TCPAdaptor {
|
2017-01-03 17:29:21 +08:00
|
|
|
address := args[0].(string)
|
2017-01-03 03:00:16 +08:00
|
|
|
|
2017-01-15 20:51:07 +08:00
|
|
|
a := NewAdaptor(address)
|
2017-01-03 03:00:16 +08:00
|
|
|
a.SetName("TCPFirmata")
|
2017-01-15 20:51:07 +08:00
|
|
|
a.PortOpener = func(port string) (io.ReadWriteCloser, error) {
|
|
|
|
return connect(port)
|
|
|
|
}
|
2017-01-03 03:00:16 +08:00
|
|
|
|
|
|
|
return &TCPAdaptor{
|
|
|
|
Adaptor: a,
|
|
|
|
}
|
|
|
|
}
|