Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printer file concurrent access

 
Nikolai Ghershun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I'm developing system,that often prints reports, and always is checking the status of printer (Low on paper, Out of paper etc...). I've implemented class, that queries printer file (/dev/usb/lp0) for status as written in printers (Swecoin TTP2030) manual, here is a code:



And out of my system this code works great. But when I integrate it in system, it starts to raise a lot of IOExceptions. I noticed that it happens when printer prints something, and in this moment I try to get status. Some times I get exception (File not found), and in this case I can check printer file like that - file.canWrite() But sometimes I can get exception (Device or resource busy) or (Input/Output error), and in this case file.canWrite() won't help. The worst thing is, that printer status enquirer not only throws exceptions, it can lock printer's file for some time. It still prints, but unavailable for enquirer.

Does exist a way to enquiry printer file while it's printing? Or maybe exists a way how to check if printer file is available. Please help!

P.S.: System is Ubuntu 12.10
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to solve your problem but surely since the printer device is a serial device and not a block device one should not use RandomAccessFile !

PS. I print on Linux but I use the printer API and have few problems. I suspect you need more control than the printer API gives you.
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Nikolai Ghershun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your fast answer.
Richard Tookey wrote:PS. I print on Linux but I use the printer API and have few problems. I suspect you need more control than the printer API gives you.


Richard, can you please describe in more details, what API you use, how, and what problems you are facing?

And also how to query serial device other way (not RandomAccessFile), because I tried simple input/output streams and they didn't work.

Thanks,
Nikolai.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general approach for interfacing with a printer would be the javax.print package.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!