[Linux-parport] user-land program for transferring data

Vinay Binny c_attitude at yahoo.com
Wed Sep 15 10:21:26 EDT 2004


Hello,

I am trying to write a small user land program for
transfer of data b/w 2 computers via parallel port. I
am using the Linux 2.4 parport system. 

While receiving data, I get the same character
repeated multiple time, if I send 'good' I receive
'gggoooooddd' at the other end. I tried using
select(fd +1, &rfds, NULL, NULL, NULL); along with
PPWCTLOIRQ and PPWCONTROL, but I was not able to catch
any interrupt. I do not know what I am doing wrong.
Pls help....

#include<fcntl.h>
#include<sys/ioctl.h>
#include<linux/ppdev.h>
#include<linux/parport.h>
#include<stdio.h>
#include<sys/times.h>
#include<sys/types.h>
#include<sys/unistd.h>
/*#include<asm/io.h>
#define nAck 0x40
#define Busy 0x80
#define nFault 0x08
struct timeval tv;*/

/*receiving program*/

int main(void){
	int fd, x, retval;
	char buf;
	int dir = 1, count;
	int mode = IEEE1284_MODE_ECP;
	fd = open("/dev/parport0" , O_RDONLY );

	x =	ioctl(fd , PPCLAIM);
	x = ioctl(fd, PPSETMODE, &mode);
	x =	ioctl(fd, PPDATADIR, &dir);
	while(1){
		x = ioctl(fd, PPRDATA, &buf);
		printf("%c", buf);
		usleep(10);
	}
	ioctl(fd, PPRELEASE);
	return 0;
}

/*Transmitting program */
{

int mode = IEEE1284_MODE_ECP;
		
fd = open("/dev/parport0",O_WRONLY | O_NONBLOCK);
fd1 = open("data",O_RDONLY);
x = ioctl(fd, PPCLAIM);
x = ioctl(fd, PPSETMODE , &mode);
do{			
	x = read ( fd1, &buf, 1 );  	
	y = ioctl(fd, PPWDATA, &buf);
	fflush(stdout);
	printf ("%c\n" , buf );
	usleep(10);
}while(x ==1);

ioctl(fd, PPRELEASE);

}




		
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 



More information about the Linux-parport mailing list