Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it only prints the first time i execute the code #54

Open
palanganero opened this issue Oct 30, 2020 · 13 comments
Open

it only prints the first time i execute the code #54

palanganero opened this issue Oct 30, 2020 · 13 comments

Comments

@palanganero
Copy link

i have to power off and power on again to do a new print.

@palanganero
Copy link
Author

once i do the escpos.close(); it does not print anymore.

@anastaciocintra
Copy link
Owner

anastaciocintra commented Oct 30, 2020

Hi @palanganero
Yes, PrinterOutputStream send data directing to the printer. The instance cannot be reused and the last command should be close(), after that, you need to create another instance to send data to the printer..

one simple way to code it is:

EscPos escpos = new EscPos(new PrinterOutputStream(printService));
// send data to the printer
escpos.close();

// again!
escpos = new EscPos(new PrinterOutputStream(printService));
// send data to the printer
escpos.close();

// and again!
escpos = new EscPos(new PrinterOutputStream(printService));
// send data to the printer
escpos.close();

@palanganero
Copy link
Author

palanganero commented Oct 30, 2020

with this code it only prints "hola holita":

 PrintService printService = PrinterOutputStream.getPrintServiceByName("xpos58");
  PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
  EscPos escpos = new EscPos(printerOutputStream);
  escpos.writeLF("Hello Wold");
  //escpos.feed(5);
  escpos.close();

 escpos = new EscPos(new PrinterOutputStream(printService));
escpos.writeLF("Hola holita");
escpos.close();

escpos = new EscPos(new PrinterOutputStream(printService));
escpos.writeLF("Hola que tal");
escpos.close();

@palanganero
Copy link
Author

palanganero commented Oct 30, 2020

the main problem i have is that when i print a ticket (after doing escpos.close()) i have to reboot the printer. It happens to me only in linux in usb mode (in ethernet mode works fine). In windows works fine. What can i try?

@anastaciocintra
Copy link
Owner

wow! have multiple configurations.
we need to divide the problems by distinct implementations of OutputStream and distinct OS.

are you using implementations from the lib?
try to make one table like this, and we can try to solve one by one ...

Platform OutputStream result
Windows PrinterOutputStream Not Ok
Windows TcpIpOutputStream Ok
Windows UsbStream Not Ok
Ubuntu PrinterOutputStream Ok
Ubuntu TcpIpOutputStream Not Ok
Ubuntu UsbStream Not Ok

@palanganero
Copy link
Author

i have ubuntu with PrinterOutputStream. it should be ok.

@anastaciocintra
Copy link
Owner

@palanganero
I runned your code, using windows and PrinterOutputStream and really, it doens't print correctly all lines.

I don't know why. but if you write a line with feed and cut. it work fine..

        escpos.writeLF("Hello Wold");
        escpos.feed(3).cut(EscPos.CutMode.FULL);
        escpos.close();

        escpos = new EscPos(new PrinterOutputStream(printService));
        escpos.writeLF("Hola holita");
        escpos.feed(3).cut(EscPos.CutMode.FULL);
        escpos.close();

        escpos = new EscPos(new PrinterOutputStream(printService));
        escpos.writeLF("Hola que tal");
        escpos.feed(7).cut(EscPos.CutMode.FULL);
        escpos.close();

@palanganero
Copy link
Author

palanganero commented Oct 30, 2020

my problem is that only prints the first time i execute the program. If i run the program again it doesn't print. If i unplug the usb cable and plug it again it prints again. But only one time. I tryed with several drivers and keeps the same. It seems to be a usb problem because if i connect the printer by ethernet it doesn't have problem. When i reboot the system it prints again.

@anastaciocintra
Copy link
Owner

Maybe some kind of driver configuration
But the problem is happening on linux only?

@palanganero
Copy link
Author

yes only in linux and by ethernet is not problem.

@anastaciocintra
Copy link
Owner

Tomorrow
I will test on my ubuntu

@anastaciocintra
Copy link
Owner

hi @palanganero

My environment is ubuntu/openjdk 11 with generic Text Only printer installed.

uname --all
Linux marcoubuntu 5.3.0-42-generic #34-Ubuntu SMP Fri Feb 28 05:49:40 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu219.10)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu219.10, mixed mode, sharing)


and, really, the code print somethig unexpected...

but if you print with one readline (enter keyboard) between print blocks it will be ok (I don't know why)

another thing is that I'm sending four lines with feed and cut (like a complete receipt) and not only one line..

                Scanner keyboard = new Scanner(System.in);
                PrintService printService = PrinterOutputStream.getPrintServiceByName("TM-T20");
                escpos = new EscPos(new PrinterOutputStream(printService));
                escpos.writeLF("Hello Wold");
                escpos.writeLF("Hello Wold");
                escpos.writeLF("Hello Wold");
                escpos.writeLF("Hello Wold");
                escpos.feed(5).cut(EscPos.CutMode.FULL);
                escpos.close();

                keyboard.nextLine();

                escpos = new EscPos(new PrinterOutputStream(printService));
                escpos.writeLF("2Hello Wold");
                escpos.writeLF("2Hello Wold");
                escpos.writeLF("2Hello Wold");
                escpos.writeLF("2Hello Wold");
                escpos.feed(5).cut(EscPos.CutMode.FULL);
                escpos.close();

                keyboard.nextLine();

                escpos = new EscPos(new PrinterOutputStream(printService));
                escpos.writeLF("3Hello Wold");
                escpos.writeLF("3Hello Wold");
                escpos.writeLF("3Hello Wold");
                escpos.writeLF("3Hello Wold");
                escpos.feed(5).cut(EscPos.CutMode.FULL);
                escpos.close();
//                keyboard.nextLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

On real world app, like server print or swing app it works well
see https://github.com/anastaciocintra/escpos-coffee-samples/blob/master/miscellaneous/server-print/src/main/java/ServerPrint.java

see you

@palanganero
Copy link
Author

ok, thank you, it should be some kind of incompatibility with the drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants