Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

opening /dev/lp0 for output

I'm creating a QT application running on RH9.  I want to send a message to the printer when certain events happen. This is the code. strMsg is a QString.

  // now print the message to the printer
  int fid = open("/dev/lp0", O_WRONLY);
  if (fid < 0)
    {
    QMessageBox::warning(this, "We Got A Problem Boss",
                        "Can't write alarms to the printer!\n");
    }
  else
    {
    // must be open if we got this far.  write the alarm message
    strMsg.append("\n");
    int intCharsOut = write(fid,strMsg, strMsg.length());
    qDebug("Wrote %d chars",intCharsOut);
    close( fid );
    qDebug("Closed the file");
    }

This code works fine ... one time.  When the code tries to print the second message, it fails to open /dev/lp0.

What changes need to be made so I can print multiple messages?

don ;{)
0
holyfeld
Asked:
holyfeld
  • 3
  • 2
1 Solution
 
Karl Heinz KremerCommented:
You may want to open the device file only once when your program starts, then write the messages to the printer, and close the file again when your program is done.
0
 
holyfeldAuthor Commented:
This works, sort of.  It does solve the "failure to open /dev/lp0" problem.  However, it also prevents lp0 from receiving print jobs from the print manager.  

ls -l lp0 returns
crw-rw-rw-    1 root     lp         6,   0 Jan 30  2003 lp0

do I need to set some other access/privilege?

don ;{)
0
 
Karl Heinz KremerCommented:
Because you are always in conflict with a print spooler when you write directly to the printer device, it's a bad idea to do this in the first place. What if you write a line, then give up the device, the printer spooler sends a job, then you open the device and print another line? Do you want your logs intermixed with normal print jobs?

I don't know how the printer port is actually controlled (haven't done this for probably ten years), but I can lookup some information for you.
0
 
holyfeldAuthor Commented:
"Because you are always in conflict with a print spooler when you write directly to the printer device, it's a bad idea to do this in the first place."

I agree.  The user will be back tomorrow.  I'll share the "news" with him and see what he says.

Can you point me to th information on who the printer port is controlled. I'm replacing a DOS application that does the open/write/close sequence with no problem.  They're using ?DesqView? and occasionally go to another window to print reports.

don ;{)
0
 
Karl Heinz KremerCommented:
There is a man page that describes the ioctl interface for the lp device (online version can be found e.g. here: http://jamesthornton.com/linux/man/lp.4.html).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now