Struct rs_openshowvar::OpenShowVar
source · 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
impl OpenShowVar
sourcepub fn new(tcp_ip: String, tcp_port: u16) -> OpenShowVar
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);sourcepub fn connect(&mut self) -> Result<()>
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),
}sourcepub fn send(&mut self, var_name: &str, val: &str) -> Result<Vec<u8>>
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),
}sourcepub fn read(&mut self, var_name: &str) -> Result<String>
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),
}sourcepub fn write(&mut self, var_name: &str, val: &str) -> Result<String>
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),
}sourcepub fn disconnect(&mut self)
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§
impl Freeze for OpenShowVar
impl RefUnwindSafe for OpenShowVar
impl Send for OpenShowVar
impl Sync for OpenShowVar
impl Unpin for OpenShowVar
impl UnwindSafe for OpenShowVar
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more