Hi, all.
My embedded board have paralled port with 25 pin. ( IO port 0x387, and SPP
mode )
I'd like to access and use it from linux...
I think I need linux parallel port device driver to access ....
I'm new to parallel port .... so If I get some simple code about how to
send a char or string...
It will give great help to me....where can I see it to learn parallel port?
(how parallel port initialize and send a char , and closing.... )
--------------------------------------------------------------
staggered into the Black Sun and said:
> My embedded board [has a] [parallel] port with 25 [pins]. ( IO port > 0x387, SPP mode.) I'd like to access and use it from linux. I think I > need [the] linux parallel port device driver to access [it] modprobe parport_pc (assuming this thing is an x86, if not, you
should've said something)
modprobe lp > I'm new to [using the] parallel port http://www.beyondlogic.org/spp/parallel.htm , OS-agnostic. Also
http://freshmeat.net/projects/parapin/ , Linux-specific.
> ... so If I get some simple code about how to send a char or > string... It will give great help to me....where can I see it to > learn parallel port? (how parallel port initialize and send a char , > and closing.... ) All whose base are belong to what?
----------------------------------------------
> (how parallel port initialize and send a char , and closing.... )
#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;
}
------------------------------------------------
楼主回答:
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 ...
ays -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 ) ;
if ( fd > 0 )
{
nbytes = write(fd, buffer , 3 );
printf ( "nbytes = ... %d\n", nbytes );
}
else
close(fd);
return 0;
}
----------------------------------------
Oops... I guess I should have compiled that once before posting. That's what I
get for composing off the top of my head.
Try this....
#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/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
{
int nbytes, total_written = 0;
while (total_written < sizeof(buffer))
{
nbytes = write(ParallelPort,
buffer + total_written,
sizeof(buffer) - total_written);
total_written += nbytes;
}
close(ParallelPort);
}
else return EXIT_FAILURE;
return EXIT_SUCCESS;
}
> #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/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
Gaak!! I thought I had corrected that error.... Change the above to
if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_SYNC)) >= 0)
The open(2) manpage says that O_DIRECT exists, but the headers disagree :-S
-------------------------------------------
DWC said:
>> nbytes = write(ParallelPort,
>> buffer + total_written,
>> sizeof(buffer) - total_written);
> Gaak!! I thought I had corrected that error.... Change the above to
> if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_SYNC)) >= 0)
write() to an fd that's been open()ed with O_RDONLY will return ...
what, precisely? I'm guessing it'll be < 0, and errno would be EBADF.
----------------------------------------
Gawd, I must have been asleep all day. Thanks, DWC for the catch on that.
Blame it on first day back after a long, exciting vacation.
---------------------------------------
------------------------------------
文章评论(0条评论)
登录后参与讨论