* ioctl fails....
@ 2004-05-16 5:13 joy
2004-05-16 9:18 ` Jan-Benedict Glaw
0 siblings, 1 reply; 2+ messages in thread
From: joy @ 2004-05-16 5:13 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 423 bytes --]
Hi,
I'm trying to do some low level data transmission using the parallel
port .in Debian, it is /dev/par0
my source is attached .perror gives me "invalid argument". if I change
the file being
opened to say, lp0, it gives me "bad file descriptor".
should I use ioperm() even in this case?
and also,is it guaranteed that the parallel port is assigend par0(I have
only one P port)?
Thanx in advance,
Joy.M.Monteiro.
[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 490 bytes --]
#include<linux/ppdev.h>
#include<stdlib.h>
#include<unistd.h>
#include<linux/parport.h>
#include<time.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<linux/ioctl.h>
main()
{
int filedes;
char data=0xff;
struct timespec time;
filedes=open("/dev/par0",O_RDWR);
if(ioctl(filedes,PPCLAIM)==-1)
perror("OPEN");
if(ioctl(filedes, PPWDATA, &data)==-1)
perror("Hi");
time.tv_sec=1;
time.tv_nsec=1000;
nanosleep(&time,NULL);
close(filedes);
return;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: ioctl fails....
2004-05-16 5:13 ioctl fails joy
@ 2004-05-16 9:18 ` Jan-Benedict Glaw
0 siblings, 0 replies; 2+ messages in thread
From: Jan-Benedict Glaw @ 2004-05-16 9:18 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1680 bytes --]
On Sun, 2004-05-16 10:43:26 +0530, joy <gracecott@sancharnet.in>
wrote in message <40A6F876.50405@sancharnet.in>:
> #include<linux/ppdev.h>
> #include<stdlib.h>
> #include<unistd.h>
> #include<linux/parport.h>
parport.h shouldn't be needed.
> #include<time.h>
> #include<sys/types.h>
> #include<sys/stat.h>
> #include<fcntl.h>
> #include<linux/ioctl.h>
For a small program I wrote, these headers were sufficient:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/ppdev.h>
Generally, try to keep the number of needed OS dependand headers small.
That keeps you informed about that needs to be ported if you ever need
to go to another OS.
> main()
> {
> int filedes;
> char data=0xff;
> struct timespec time;
> filedes=open("/dev/par0",O_RDWR);
> if(ioctl(filedes,PPCLAIM)==-1)
> perror("OPEN");
>
> if(ioctl(filedes, PPWDATA, &data)==-1)
> perror("Hi");
> time.tv_sec=1;
> time.tv_nsec=1000;
> nanosleep(&time,NULL);
> close(filedes);
> return;
> }
The code itself looks okay technically (well, early exit on failure
would be nice:), but I suspect that you're using a wrong device. Is your
device /dev/par0 a char-dev with major=99 and minor=0? Is the ppdev
driver loaded?
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak!
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-05-16 9:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-16 5:13 ioctl fails joy
2004-05-16 9:18 ` Jan-Benedict Glaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).