ioctl fails....
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.
#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;
}On Sun, 2004-05-16 10:43:26 +0530, joy <[email protected]> wrote in message <[email protected]>:
Quoted 4 lines
#include<linux/ppdev.h>
#include<stdlib.h>
#include<unistd.h>
#include<linux/parport.h>
parport.h shouldn't be needed.
Quoted 5 lines
#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.
Quoted 17 lines
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
Signature · 4 lines
Jan-Benedict Glaw [email protected] . +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));