pub struct OpenShowVar {
    pub conn: Option<TcpStream>,
    /* private fields */
}
Expand description

The OpenShowVar structure is used to connect to a robot control system and read/write variable values over a TCP connection.

Fields§

§conn: Option<TcpStream>

TCP connection.

Implementations§

source§

impl OpenShowVar

source

pub fn new(tcp_ip: String, tcp_port: u16) -> OpenShowVar

Creates a new instance of OpenShowVar.

§Arguments
  • tcp_ip - IP address of the TCP server to connect to.
  • tcp_port - Port number of the TCP server to connect to.
§Returns

Returns a new instance of OpenShowVar.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
source

pub fn connect(&mut self) -> Result<()>

Connects to the TCP server.

§Returns

Returns Ok(()) if the TCP connection is successful. Returns std::io::Error if the TCP connection fails.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
match osv.connect() {
    Ok(_) => println!("Connection successful"),
    Err(e) => println!("Connection error: {}", e),
}
source

pub fn send(&mut self, var_name: &str, val: &str) -> Result<Vec<u8>>

Sends a variable value.

§Arguments
  • var_name - Name of the variable to send.
  • val - Value of the variable to send.
§Returns

Returns a std::io::Result depending on the sent data.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
match osv.send("variable_name", "value") {
    Ok(data) => println!("Data sent: {:?}", data),
    Err(e) => println!("Sending error: {}", e),
}
source

pub fn read(&mut self, var_name: &str) -> Result<String>

Reads the specified variable.

§Arguments
  • var_name - Name of the variable to read.
§Returns

Returns the read variable value inside std::io::Result<String>.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
match osv.read("variable_name") {
    Ok(val) => println!("Read value: {}", val),
    Err(e) => println!("Reading error: {}", e),
}
source

pub fn write(&mut self, var_name: &str, val: &str) -> Result<String>

Writes a value to the specified variable.

§Arguments
  • var_name - Name of the variable to write.
  • val - Value to write to the variable.
§Returns

Returns the written variable value inside std::io::Result<String>.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
match osv.write("variable_name", "value") {
    Ok(val) => println!("Written value: {}", val),
    Err(e) => println!("Writing error: {}", e),
}
source

pub fn disconnect(&mut self)

Terminates the TCP connection.

§Example
use rs_openshowvar::OpenShowVar;
let mut osv = OpenShowVar::new("127.0.0.1".to_string(), 7000);
osv.disconnect();

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.