esc-pos-lib 0.1.6

A library for printing to ESC/POS compatible printers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::net::TcpStream;
use std::io::prelude::*;

///Establishes a tcpsocket with a printer.
///Sends the message in the Vec<u8>
pub fn send_message(msg: &Vec<u8>, mut address: String, port: u32) -> Result<(), String> {
    
    address.push_str(":");
    address.push_str(&port.to_string());
    let mut stream = match TcpStream::connect(address) {
        Ok(stream) => stream,
        Err(e) => return Err(e.to_string()),
    };
    match stream.write(&msg[0..]) {
        Ok(_) => Ok(()),
        Err(e) => Err(e.to_string()),
    }
}