Re: seng a character to printer port...



google-rambo88 <rambo88@xxxxxxxxx> wrote:
Very strange... even though I include all header files... related open()
function...
( #include <sys/types.h> ,#include <sys/stat.h>,#include <fcntl.h> )
I met " `O_DIRECT' undeclared (first use in this function) "


so I remove it for compiling.. And write() function returned
...always -1..


when I run this short example, I can see following messages by runing
"dmesg" command.

parport0: PC-style at 0x378 [PCSPP,EPP]
parport0: faking semi-colon
parport0: Printer, Hewlett-Packard HP LaserJet 1100
lp0: using parport0 (polling).
lp0: console ready

Why I can't write character to /dev/lp0?


I 'd like to know How they are diffrect between /dev/lp0 and /dev.par0 and
/dev/parport0 ?


========
========================================================
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(void)
{
int fd;
int nbytes, total_written = 0;
char buffer[3] = {0x65, 0x0D , 0x0a };

fd = open("/dev/lp0",O_RDONLY| O_SYNC ) ;
=========================^^^^^^

Why are you opening it for read if you're planning on _writing_ to it?

Jerry

if ( fd > 0 )
{

nbytes = write(fd, buffer , 3 );
printf ( "nbytes = ... %d\n", nbytes );
}
else

close(fd);
return 0;
}



Have a day....


#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(void)
{
int ParallelPort;
char buffer[1] = "A";

if ((ParallelPort = open("/dev/lp0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
{
int nbytes, total_written = 0;
while (bytes_written < sizeof(buffer)
{
nbytes = write(ParallelPort, buffer + total_written,
sizeof(buffer) - total_written);
total_written += nbytes;
}

close(ParallelPort);
}
else return EXIT_ERROR;
return EXIT_SUCCESS;
}





.



Relevant Pages