LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   lpt bash command (https://www.linuxquestions.org/questions/programming-9/lpt-bash-command-406266/)

ell 01-21-2006 02:57 PM

lpt bash command
 
Hello everyome!

I want to develop a littel program to control lpt port (project in electronic).

Someone know command (or site with command) to do this?

Sorry for very bad English..
Thanks, ell!

paulsm4 01-21-2006 03:18 PM

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:

http://lwn.net/Kernel/LDD3/

'Hope that helps .. PSM

ell 01-21-2006 03:44 PM

bash=c?!

I'm new in linux..

Thanks, ell!

paulsm4 01-21-2006 08:04 PM

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".

These links might be of some use:
http://www.torque.net/linux-pp.html
http://www.epanorama.net/circuits/parallel_output.html
http://www.lvr.com/jansfaq.htm

Sorry I can't be of more help .. PSM

ell 01-22-2006 02:28 PM

First, Thank you for the help!

If I understand you good, there is no option to control in circuits like this:
www
.epanorama.net/circuits/lptleds.gif
in Bash?

Thank you for your help!
ell

paulsm4 01-22-2006 02:43 PM

Hi -

There's ALWAYS a way - depending on how tricky and clever you want to get.

But no, as far as I know, this is probably a job for 'C' (or a similar systems-level language).

Sorry I can't be of more help ... and I'm 100% prepared to be wrong ;-)

Your .. PSM

ell 01-22-2006 03:43 PM

O.K.
Thank you for the information!
Have a nice day!
ell


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