Java realizes the control of the network printer and completes the lost single __java mechanism.

Source: Internet
Author: User
Tags print object

In the catering industry commonly used in the ordering system, printing list is a basic function. In the catering, the general use of POS printers. However, in many order-ordering systems, it is a very painful thing to lose. In this paper, how to use the Java implementation to bypass the driver control printing and to achieve the loss of a single processing, a solution.

The requirement for this article is that a document is printed at the same time by multiple printers, and you will need to reprint a document if it does not print successfully. After you connect the printer to the router and determine that the printer is normal, you can test it.

The implementation of this article is: the use of queues and threading operations to complete.

This article establishes several objects:

1, Printer object printer: Printer number, printer IP, printer port, default paper width, etc.

2, Print object printableobject: encapsulation needs to print the information

3, Print Job Object printjob: Encapsulate a Printableobject object, contain a state bit, possible state has "wait to print", "Printing", "Finish printing". Also contains a print method.

4, print queue printqueue: Single instance, simulate a queue, where the method is thread-safe. Each element is a PrintJob object, FIFO, print failure, and return to the tail of the queue.

5, Print Grab object Printabletracker: This object is a thread, and is a single-instance. Keep the printjob from PrintQueue, print successfully, continue printing next, otherwise, move the current to the end of the queue, continue printing the next. If there is no printjob in the queue, it ends. When you add PrintJob to printqueue again, the thread starts to print.

6, Printutils: Refer to the printer's own command manual, packaging printing commands, in the PrintJob Print method call Printutils package of commands to print. In the Print method, establish a socket connection and communicate with the printer.


The above realization, in the good Bo heat-sensitive network mouth printer test pass. Solve the problem of losing a single problem due to network problems or problems with the printer but paper. However, when the print command has been routed to the outside, and at this point the printer is out of power, the phone cannot be printed again. Because in the program, the operation is actually completed, but these commands exist in the network or the printer cache, the information does not exist after the power outage. This is because the printer cannot tell if the printer is out of paper. Not found at least from the Print command Manual of the good Bo. However, if other printers can, you can receive this status in the socket to determine if the printing was successful. In this way, the probability of losing a single is even smaller.


The idea is this, for reference only.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.