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

Thiago Augusto Miranda Delatorre tdlt at cecm.usp.br
Wed Sep 15 19:05:00 EDT 2004


On Wed, Sep 15, 2004 at 07:21:26AM -0700, Vinay Binny wrote:
> 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....

Shouldn't you use a protocol where you ask for more data or notice to
the other system whether or not you had received the data sent?

> 
> #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 
> 
> _______________________________________________
> Linux-parport mailing list
> Linux-parport at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-parport

-- 
Thiago A. M. Delatorre



More information about the Linux-parport mailing list