-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from fabienbellanger/printerStatus
Add printer status
- Loading branch information
Showing
13 changed files
with
559 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use escpos::printer::Printer; | ||
use escpos::utils::*; | ||
use escpos::{driver::*, errors::Result}; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
fn main() -> Result<()> { | ||
env_logger::init(); | ||
|
||
let driver = NetworkDriver::open("192.168.1.248", 9100)?; | ||
// let driver = ConsoleDriver::open(true); | ||
// let driver = UsbDriver::open(0x0525, 0xa700, None)?; | ||
|
||
loop { | ||
Printer::new(driver.clone(), Protocol::default(), None) | ||
.debug_mode(Some(DebugMode::Dec)) | ||
.real_time_status(RealTimeStatusRequest::Printer)? | ||
.real_time_status(RealTimeStatusRequest::RollPaperSensor)? | ||
.send_status()?; | ||
|
||
// From Epson documentation: if this command must be transmitted continuously, | ||
// it is possible to transmit up to 4 commands at once. | ||
let mut buf = [0; 2]; | ||
driver.read(&mut buf)?; | ||
|
||
// Online/Offline status | ||
let status = RealTimeStatusResponse::parse(RealTimeStatusRequest::Printer, buf[0])?; | ||
println!( | ||
"Printer online: {}", | ||
status.get(&RealTimeStatusResponse::Online).unwrap_or(&false) | ||
); | ||
|
||
// Roll paper near-end sensor status | ||
let status = RealTimeStatusResponse::parse(RealTimeStatusRequest::RollPaperSensor, buf[1])?; | ||
println!( | ||
"Roll paper near-end sensor => paper adequate: {}", | ||
status | ||
.get(&RealTimeStatusResponse::RollPaperNearEndSensorPaperAdequate) | ||
.unwrap_or(&false) | ||
); | ||
|
||
sleep(Duration::from_secs(10)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.