1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-14 19:29:32 +08:00
hybridgroup.gobot/platforms/firmata/tcp_firmata_adaptor.go
Thomas Kohler 865e724af0
Build(v2): revert move to v2 subfolder (#932)
* revert move to v2 subfolder
* fix CI and adjust CHANGELOG
2023-05-29 19:23:28 +02:00

35 lines
669 B
Go

package firmata
import (
"io"
"net"
"gobot.io/x/gobot/v2"
)
// TCPAdaptor represents a TCP based connection to a microcontroller running
// WiFiFirmata
type TCPAdaptor struct {
*Adaptor
}
func connect(address string) (io.ReadWriteCloser, error) {
return net.Dial("tcp", address)
}
// NewTCPAdaptor opens and uses a TCP connection to a microcontroller running
// WiFiFirmata
func NewTCPAdaptor(args ...interface{}) *TCPAdaptor {
address := args[0].(string)
a := NewAdaptor(address)
a.SetName(gobot.DefaultName("TCPFirmata"))
a.PortOpener = func(port string) (io.ReadWriteCloser, error) {
return connect(port)
}
return &TCPAdaptor{
Adaptor: a,
}
}