LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Printer Port Programming (http://www.linuxquestions.org/questions/programming-9/printer-port-programming-174923/)

keikun_naruchan 04-26-2004 09:43 PM

Printer Port Programming
 
hi, I would just like to ask if any of you out there know how to program printer ports, I would like to know how to create a program that would allow me to access the printer and print, programming language to be used can be anything... tnx.... HOPE YOU COULD HELP ME....

itsme86 04-26-2004 10:58 PM

Code:

int main(void)
{
  FILE *fp = fopen("/dev/lp0", "w");

  fprintf(fp, "This should print to the printer.\r\n");
  fflush(fp);
  fclose(fp);
}


keikun_naruchan 04-27-2004 12:53 AM

reply
 
um, i think your code will only work in a linux environment, im sorry i forget to include in my previos post that i need code that would be implemented in a windows environment, tnx, m sorry again

zekko 04-27-2004 01:26 AM

Standard printer (stdprn) is automatically opened when you include stdio.h (just like stdout, stdin ...).

keikun_naruchan 04-27-2004 01:48 AM

reply 2 zekko:

um, could you explain what you just said, im not following you, i think what your talking about is the header files that can be used in c, could you please give me code to access the printer port so that i could print using a program or just provide me links to documents regarding this topic, tnx,,, hope you understand...

fahim 04-27-2004 07:01 AM

Since u wanted to program in the windows probabbly vb u have go thorough some difficult tasks.If u definitely wnated i will let u know.But in C it is very easy.

printer port addresses are 0X378,379,37a

the command in c is
outportb(0X378,###)
###-value that u wanted to sent to the port in binary
reading the value
inportb(address)
reads the particular add.
if u want further details in c or vb contact me
my mail is
cmmfahim@yahoo.com

I am an engineering graduate

fahim 04-27-2004 07:03 AM

Since u wanted to program in the windows probabbly vb u have go thorough some difficult tasks.If u definitely wnated i will let u know.But in C it is very easy.

printer port addresses are 0X378,379,37a

the command in c is
outportb(0X378,###)
###-value that u wanted to sent to the port in binary
reading the value
inportb(address)
reads the particular add.
if u want further details in c or vb contact me
my mail is
cmmfahim@yahoo.com

I am an engineering graduate

If it is a priin ting program that u want ot print using the language i am not the one that u wanted

itsme86 04-27-2004 09:13 AM

Re: reply
 
Quote:

Originally posted by keikun_naruchan
um, i think your code will only work in a linux environment, im sorry i forget to include in my previos post that i need code that would be implemented in a windows environment, tnx, m sorry again
Well yeah, this is linuxquestions.org you know :rolleyes:

zekko 04-27-2004 09:26 AM

Code:

int main(void) {
    int i;

    fputs("\r\n", stdprn);
    for (i = 0; i < 50; i++)
        fprintf(stdprn, "%d ... Lets hope this works ...\r\n", i);
    fputs("\r", stdprn);
    return 0;
}

This code should work .. I remember it printing out but it wouldn't eject the paper when done printing. I think this may be because I should be sending formfeed ( fputs("\f", stdprn) ). You have to play around with it a little bit ...

keikun_naruchan 04-27-2004 09:09 PM

Re: reply ( post #8)


quote:
--------------------------------------------------------------------------------
Originally posted by keikun_naruchan
um, i think your code will only work in a linux environment, im sorry i forget to include in my previos post that i need code that would be implemented in a windows environment, tnx, m sorry again
--------------------------------------------------------------------------------



Well yeah, this is linuxquestions.org you know

reply:

I know this is linuxquestions.org, but did you happen to understand what the general title of this forum is, it is NON-LINUX PROGRAMMING.. understand????


*****this is what is wriiten on the forums title*****
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

keikun_naruchan 04-27-2004 09:14 PM

reply to zekko:

WOW just few lines of code and it is already supposed to communicate with my printer and print.. tnx.. could you include the headers needed for this code to work, i understand that this code is in c++ or in c language am i right?, tnx again..

zekko 04-27-2004 11:31 PM

Oh I'm sorry, you need to include stdio.h

Code:

#include <stdio.h>

int main(void) {
    int i;

    fputs("\r\n", stdprn);
    for (i = 0; i < 50; i++)
        fprintf(stdprn, "%d ... Lets hope this works ...\r\n", i);
    fputs("\r\f", stdprn);
    return 0;
}

This is C code, but should work with a C++ compiler (just like all C code).

One weird thing, it doesn't start printing until the program stops running (even if I fflush(stdprn)). I'm not sure why this is, could just be my printer.

keikun_naruchan 04-28-2004 12:29 AM

um, could you explain your code, what is stdprn and the sorts..
I would like to know what is within stdprn... its parameters and its functions... its quite advance programming for me.. tnx.. hope you still have patience with me...
tnx again...

reply: 4 zekko

zekko 04-28-2004 06:38 PM

If you're learning from a book, it should teach how to work with files ... You'll learn how this all works once you get to there.

mr_rich 03-07-2011 06:23 PM

Quote:

Originally Posted by keikun_naruchan (Post 900992)
um, i think your code will only work in a linux environment, im sorry i forget to include in my previos post that i need code that would be implemented in a windows environment, tnx, m sorry again

If you use Visual Studio 2008 C++ express you will need: microsoft platform SDK. and
You can download and compile winio32.dll (there are examples of using this .dll on the internet).
by itsself then add the following files out of folder:

These files: are needed for compiling with visual studio express 2008.

Place "winio32.obj" "winio.h" in with project library and source files.

Place the driver files out of dll folder with the source files "..\drv\winio_nt.h" you will have to change this to: "winio_nt.h" with source files in folder- unless you link to folder.

Place winio32.dll and winio32.sys with binary.


All times are GMT -5. The time now is 03:54 AM.