ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Assuming you're programming in C/C++, the easiest approach is something like this:
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
...
int fd = open ("/dev/lp0", O_RDWR|O_DIRECT, 0);
if (fd < 0)
perror ("Unable to open lp port!\n");
... construct some data to send to the printer port ...
int iret = write (fd, buff, ct);
if (iret < ct)
perror ("I/O failure during write!\n");
... read some data back from the printer port ...
iret = read (fd, buff, ct);
if (iret < 0)
perror ("I/O failure during read!\n");
... Done processing ...
close (fd);
...
Although the standard "open/read/write" APIs are probably the best place to start, there are lots and lots of other alternatives available to you, depending on what your requirements are and/or what language(s) you're programming in.
For example, the O'Reilly "Linux Device Drivers" book has a whole chapter (Chap 9) on interfacing a custom kernel driver to your parallel port:
Sorry - I didn't notice your title line, I just read your text:
Quote:
I want to develop a littel program to control lpt port
If you simply want to print stuff, "lp" is the command; "cups" is generally the subsystem.
But, AFAIK, if you "want to control the LPT port" (separate and distinct from simply spooling stuff to the printer), you're probably going to have to use some programming language other than "bash".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.