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. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-26-2004, 09:43 PM
|
#1
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Rep:
|
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....
|
|
|
|
04-26-2004, 10:58 PM
|
#2
|
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
Code:
int main(void)
{
FILE *fp = fopen("/dev/lp0", "w");
fprintf(fp, "This should print to the printer.\r\n");
fflush(fp);
fclose(fp);
}
|
|
|
|
04-27-2004, 12:53 AM
|
#3
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Original Poster
Rep:
|
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
|
|
|
|
04-27-2004, 01:26 AM
|
#4
|
|
Member
Registered: Aug 2003
Location: Canada
Distribution: Slackware, debian
Posts: 76
Rep:
|
Standard printer (stdprn) is automatically opened when you include stdio.h (just like stdout, stdin ...).
|
|
|
|
04-27-2004, 01:48 AM
|
#5
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Original Poster
Rep:
|
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...
|
|
|
|
04-27-2004, 07:01 AM
|
#6
|
|
LQ Newbie
Registered: Apr 2004
Location: Sri Lanka
Distribution: Red Hat 8
Posts: 3
Rep:
|
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
|
|
|
|
04-27-2004, 07:03 AM
|
#7
|
|
LQ Newbie
Registered: Apr 2004
Location: Sri Lanka
Distribution: Red Hat 8
Posts: 3
Rep:
|
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
|
|
|
|
04-27-2004, 09:13 AM
|
#8
|
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
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 
|
|
|
|
04-27-2004, 09:26 AM
|
#9
|
|
Member
Registered: Aug 2003
Location: Canada
Distribution: Slackware, debian
Posts: 76
Rep:
|
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 ...
Last edited by zekko; 04-27-2004 at 09:29 AM.
|
|
|
|
04-27-2004, 09:09 PM
|
#10
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Original Poster
Rep:
|
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.
|
|
|
|
04-27-2004, 09:14 PM
|
#11
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Original Poster
Rep:
|
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..
|
|
|
|
04-27-2004, 11:31 PM
|
#12
|
|
Member
Registered: Aug 2003
Location: Canada
Distribution: Slackware, debian
Posts: 76
Rep:
|
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.
|
|
|
|
04-28-2004, 12:29 AM
|
#13
|
|
LQ Newbie
Registered: Feb 2004
Distribution: Suse, LFS(Linux From Scratch)
Posts: 20
Original Poster
Rep:
|
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
Last edited by keikun_naruchan; 04-28-2004 at 12:33 AM.
|
|
|
|
04-28-2004, 06:38 PM
|
#14
|
|
Member
Registered: Aug 2003
Location: Canada
Distribution: Slackware, debian
Posts: 76
Rep:
|
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.
|
|
|
|
03-07-2011, 06:23 PM
|
#15
|
|
LQ Newbie
Registered: Mar 2011
Posts: 1
Rep:
|
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
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:34 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|