Struct tinkerforge::ip_connection::IpConnection
source · pub struct IpConnection { /* private fields */ }
Expand description
The IP Connection manages the communication between the API bindings and the Brick Daemon or a WIFI/Ethernet Extension. Before Bricks and Bricklets can be controlled using their API an IP Connection has to be created and its TCP/IP connection has to be established.
Implementations
sourceimpl IpConnection
impl IpConnection
sourcepub fn new() -> IpConnection
pub fn new() -> IpConnection
Creates an IP Connection object that can be used to enumerate the available devices. It is also required for the constructor of Bricks and Bricklets.
sourcepub fn get_request_sender(&self) -> IpConnectionRequestSender
pub fn get_request_sender(&self) -> IpConnectionRequestSender
Returns a new request sender, to be used for example in other threads.
sourcepub fn connect<T: ToSocketAddrs>(
&self,
addr: T
) -> Receiver<Result<(), ConnectError>>
pub fn connect<T: ToSocketAddrs>(
&self,
addr: T
) -> Receiver<Result<(), ConnectError>>
Creates a TCP/IP connection to the given host
and port
. The host and port can refer to a Brick Daemon or to a WIFI/Ethernet Extension.
Devices can only be controlled when the connection was established successfully.
Returns a receiver, which will receive either ()
or an ConnectError
if there is no Brick Daemon or WIFI/Ethernet Extension listening at the given host and port.
sourcepub fn disconnect(&self) -> Receiver<Result<(), DisconnectErrorNotConnected>>
pub fn disconnect(&self) -> Receiver<Result<(), DisconnectErrorNotConnected>>
Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.
sourcepub fn get_connect_callback_receiver(&self) -> Receiver<ConnectReason>
pub fn get_connect_callback_receiver(&self) -> Receiver<ConnectReason>
This event is triggered whenever the IP Connection got connected to a Brick Daemon or to a WIFI/Ethernet Extension.
sourcepub fn get_disconnect_callback_receiver(&self) -> Receiver<DisconnectReason>
pub fn get_disconnect_callback_receiver(&self) -> Receiver<DisconnectReason>
This event is triggered whenever the IP Connection got disconnected from a Brick Daemon or to a WIFI/Ethernet Extension.
sourcepub fn get_timeout(&self) -> Duration
pub fn get_timeout(&self) -> Duration
Returns the timeout as set by set_timeout
sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Sets the timeout for getters and for setters for which the response expected flag is activated.
Default timeout is 2500 ms.
sourcepub fn get_connection_state(&self) -> ConnectionState
pub fn get_connection_state(&self) -> ConnectionState
Queries the current connection state.
sourcepub fn get_auto_reconnect(&self) -> bool
pub fn get_auto_reconnect(&self) -> bool
Returns true if auto-reconnect is enabled, false otherwise.
sourcepub fn set_auto_reconnect(&mut self, auto_reconnect_enabled: bool)
pub fn set_auto_reconnect(&mut self, auto_reconnect_enabled: bool)
Enables or disables auto-reconnect. If auto-reconnect is enabled, the IP Connection will try to reconnect to
the previously given host and port, if the currently existing connection is lost.
Therefore, auto-reconnect only does something after a successful connect
call.
Default value is true.
sourcepub fn enumerate(&self)
pub fn enumerate(&self)
Broadcasts an enumerate request. All devices will respond with an enumerate event.
sourcepub fn get_enumerate_callback_receiver(
&self
) -> ConvertingCallbackReceiver<EnumerateResponse>
pub fn get_enumerate_callback_receiver(
&self
) -> ConvertingCallbackReceiver<EnumerateResponse>
This receiver receives enumerate events, as described here.
sourcepub fn authenticate(
&self,
secret: &str
) -> Result<ConvertingReceiver<()>, AuthenticateError>
pub fn authenticate(
&self,
secret: &str
) -> Result<ConvertingReceiver<()>, AuthenticateError>
Performs an authentication handshake with the connected Brick Daemon or WIFI/Ethernet Extension. If the handshake succeeds the connection switches from non-authenticated to authenticated state and communication can continue as normal. If the handshake fails then the connection gets closed. Authentication can fail if the wrong secret was used or if authentication is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.
See the authentication tutorial for more information.
New in version 2.1.0.