fabienbellanger / escpos-rs

ESC/POS implementation in Rust
https://docs.rs/escpos
Other
27 stars 12 forks source link

Error: Input("invalid UTF-8")错误 #31

Open yidanfun opened 3 weeks ago

yidanfun commented 3 weeks ago

首先感谢作者创作了如此优秀的作品!我是中文用户,在运行example/debug示例时,会提示:

Error: Input("invalid UTF-8") error: process didn't exit successfully: target\debug\testescpos.exe (exit code: 1)

示例中使用的Driver是ConsoleDriver,我使用了NetworkDriver,其他没做任何改动,结果提示以上错误。 因为我对Rust掌握并不好,尝试跟踪了一下,发现只要调用writeln()方法就会出现错误。储如print_cut()是可以执行的。

请问这是什么原因?我用之前的0.12.2版本测试是可以正常打印中文的。

出问题的开发环境如下: rustc 1.80.1 (3f5fd8dd4 2024-08-06) tauri = { version = "2.0.0-rc", features = [] } escpos = { version = "0.13.0", features = ["full"] }

Thanks!

fabienbellanger commented 3 weeks ago

Hi, Could you give me some more details? Do you have an example of code I could test?

yidanfun commented 2 weeks ago

Thanks for your reply!,my main.rs:

use escpos::printer::Printer;
use escpos::utils::*;
use escpos::{driver::*, errors::Result};

fn main() -> Result<()> {
    env_logger::init();

    let driver = NetworkDriver::open("192.168.1.66", 9100, None)?;
    //let driver = ConsoleDriver::open(true);
    Printer::new(driver,  Protocol::default(), None)
        .debug_mode(Some(DebugMode::Dec))
        .init()?
        .smoothing(true)?
        // .bold(true)?
        // .underline(UnderlineMode::Single)?
        // .writeln("Bold underline")?
        // .justify(JustifyMode::CENTER)?
        // .bold(false)?
        // .underline(UnderlineMode::None)?
        // .size(2, 3)?
         .writeln("abc")? 
         .print_cut()?
         .debug()?;

    Ok(())
}

Cargo.toml file:

[package]
name = "testescpos"
version = "0.1.0"
edition = "2021"

[dependencies]
env_logger = "0.11.5"
escpos = { version = "0.13.0", features = ["full"] }

Nothing more!

My OS is Windows11. A picture may be more clear: rustescpos

`

fabienbellanger commented 2 weeks ago

Hi, I tested your example code by simply changing the IP address on Mac OS 14.6 and Windows 10 with the 0.13.0 version, and it works fine. The ticket prints correctly from the two machines.

Do you have the same problem with another driver (Console, Usb, etc.)?

yidanfun commented 2 weeks ago

I got the same error with ConsoleDriver. If I comment the WriteLn() line, it will work correctly and print "bVA" in console. UsbDriver and NativeUsbDirver cant work on my Windows11 PC. My thermal print is XPrinter XP-80C, it dosen't list in DeviceManager, so I can't get VID and PID. I drived my USB printer by another Win32 API.