Using the printer from a C program !!

Using the printer from a C program !!

Post by pandapow » Wed, 25 Jun 2003 17:02:58



hi,
  This is the first time iam dealing with printers on linux and so
have a limited knowledge.I will be controlling a printer attached to
the printer port.Now with the docs i have been going throught on the
net, these are some of the ways i summed up :
1.Users can directly use lpr - but i want to control it from my
program

2.Using the lpd daemon - making a connection to the port on which the
daemon is running.Iam not totally clear about the functions of lpr and
lpd, and if at all this suitable for my case, how is it done ?

3.Use the /dev/lpx device - open the device and read and write like a
normal file and also use the IOCTLS.I dont have the IOCTLS list for
the printer.Maybe this is the right thing in my case to do.How can i
check whether a printer is configured/attached to my computer?Point me
to some examples if possible.

4.Directly accessing the port by ioperm or /dev/port as mentioned in
IO-port programming.I think this is mostly required if iam trying to
control some other device from the parallel port.But in my case its a
printer.So i guess this low level access can be used but is not
required.

There maybe many other ways also(like i read that we can use the
printer using the termios calls too,dont know how thats done,unless
ofcourse my printer is connected to the serial port), iam in a dillema
as to which one is suitable in my case.I also need to do some control
like checking whether printer is ONLINE/OFFLINE/BUSY or is configured
or not and whether attached or not etc.

Any help will be highly appreciated.
rohit

 
 
 

Using the printer from a C program !!

Post by Sybren Stuve » Wed, 25 Jun 2003 17:29:38


pandapower enlightened us with:

Quote:> 1.Users can directly use lpr - but i want to control it from my
> program

You can use lpr directly from your program too. Many program offer an
input box for their users where they can modify the lpr command &
parameters used, and then simply fork() and exec() lpr.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?

 
 
 

Using the printer from a C program !!

Post by Thomas Richte » Wed, 25 Jun 2003 17:36:23


Hi,

Quote:>   This is the first time iam dealing with printers on linux and so
> have a limited knowledge.I will be controlling a printer attached to
> the printer port.Now with the docs i have been going throught on the
> net, these are some of the ways i summed up :
> 1.Users can directly use lpr - but i want to control it from my
> program

This is probably the best option. One of the problems of *ix is that
"you never know how the print command is called today", so leave this to
the user. Open a pipe, fork(), and feed an exec'd lpr thru stdin from the
forked process, feed the pipe from your program side. Plus, let the user
choose how the print command is called. Most flexible, I'd say, and most
portable.

Greetings,
        Thomas

 
 
 

Using the printer from a C program !!

Post by Mario Klebs » Thu, 26 Jun 2003 05:57:50



>1.Users can directly use lpr - but i want to control it from my
>program
>2.Using the lpd daemon - making a connection to the port on which the
>daemon is running.Iam not totally clear about the functions of lpr and
>lpd, and if at all this suitable for my case, how is it done ?

Try to combine 1&2:

        #include <stdio.h>

        FILE *f=popen("lpr","w");
        fprintf(f,"Hello World\n");
        pclose(f);

Of course, error checking has to be added, like when writing to a file.

73, Mario
--

PGP-Key available at http://www.klebsch.de/public.key
Fingerprint DSS: EE7C DBCC D9C8 5DC1 D4DB  1483 30CE 9FB2 A047 9CE0
 Diffie-Hellman: D447 4ED6 8A10 2C65 C5E5  8B98 9464 53FF 9382 F518

 
 
 

Using the printer from a C program !!

Post by pandapow » Fri, 27 Jun 2003 14:01:51


There are terminal escape codes to query the status of the printer
device.I sent the vt100(linux is compatible to vt100 i suppose)escape
sequence "ESC [ ? 1 5 n " to request printer status , i should have
got some kind of report which should again be a escape sequence of the
status of the printer.Has anybody tried this so you could help me.I
also tried "ESC [ 5 n         request for terminal status" and it
gives me the correct output, but my request for printer status is
failing.Iam using a c-program,and i pass the escape code which it
prints on the screen and i can see the report escape code printed on
the screen(this is if you have given a request).

any help will be highly appreciated.thanks for all your suggestions.

rohit

 
 
 

Using the printer from a C program !!

Post by v.. » Fri, 27 Jun 2003 14:20:21




>There are terminal escape codes to query the status of the printer
>device.I sent the vt100(linux is compatible to vt100 i suppose)escape
>sequence "ESC [ ? 1 5 n " to request printer status , i should have
>got some kind of report which should again be a escape sequence of the
>status of the printer.

... attached to the (physical) terminal in question.  Which is completely
meaningless in this case - simply because there is no printers attached
to virtual consoles (let alone xterms and their ilk).

IOW, it does not work and it will not work.

 
 
 

1. Please help find a program to print on remote printer (not using /etc/printcap)

Hello,
 Could you please help me to find a program that would just connect to the
remote machine's printer daemon and send a printer job to it (just print a
file). The reason I am asking is that only several people out of few
thousand are going to use that remote printer and the sys.adm is not
willing to add an entry to /etc/printcap.


--
   Nick
----------[  2*2=2*(1+1)=2*1+2*1=2+2=2+(1+1)=(2+1)+1=3+1=4  ]-----------

2. problem with driver cmipci and audacity

3. Using the printer control program: klpq

4. Question on upgrade from Sol 10 to 10 1/06

5. Using printer as network printer

6. HELP!!!!................PLEASE

7. Printer setup using NetBSD-1.3 and HP 692c Deskjet Printer

8. $2000 to spend on computer stuff

9. Using a printer from the printer port of a term conn to a Unix comp

10. Different printer models using same printer

11. Printer feedback from PostScript printer using piobe?

12. Using PC-driven printers ans UNIX remote printer ???

13. Add Printer using CUPS web interface- View Printer in OpenOffice Delayed, Why?