|
||||||||
|
|
#1
|
|
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.... /*CODE for transmitting data*/ #include<fcntl.h> #include<stdio.h> #include<errno.h> #include<sys/ioctl.h> #include<linux/ppdev.h> #include<linux/parport.h> #include<unistd.h> #define BASE 0x378 int main(void){ int fd; int mode; char buf; size_t got = 1; int fd1, j=0; int dir =0;// direction is 0 coz we need to transmit /*Open the serial port for writing*/ fd = open ("/dev/parport0" , O_RDWR); /* Open the file in which data to be transmitted is present*/ fd1 = open("par",O_RDONLY); /*gain access or permission for the port*/ if (ioctl (fd, PPCLAIM)) /*assign mode */ mode = IEEE1284_MODE_COMPAT; /*set the desired mode*/ ioctl (fd, PPNEGOT, &mode); /*set the direction of data flow(write) */ ioctl(fd, PPDATADIR, &dir); /*until 1 or more character is there to read in the file*/ for (;got == 1 {/*read from the data file*/ got = read (fd1 , &buf, 1); /*Write to the serial port*/ ioctl (fd, PPWDATA, &buf); /*print the written data */ fflush(stdout); printf("%c\n", buf); /*delay a bit*/ usleep(1000); /*output a value to control register*/ ioctl(fd, PPWCONTROL, &j); j++; /*if 5th bit of Control register is set, the data lines cannot output data but they can only read, hence j is changed from 1 to 31. i.e all the 4 bits of control register are used*/ if(j == 31) j=0; } } /*End of code for transmitting data*/ I am printing out the received data in the CODE for receivng data. /*CODE for receiving data*/ #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<signal.h> int fd; /* this catcher() func is invoked when ctrl-C is pressed*/ catcher(){ ioctl(fd, PPRELEASE); exit(); } int main(void){ int retval; char buf; int dir = 1; //since we are receiving data, direction should be 1 int mode = IEEE1284_MODE_COMPAT; //used as a parameter to set mode char ch; /* Open the serial port */ fd = open("/dev/parport0" , O_RDONLY ); /*catcht ctrl-c*/ signal(SIGINT, catcher); /*gain access or claim the parallel port*/ ioctl(fd , PPCLAIM); /*set the desired mode of communication(COMPAT in this case*/ ioctl(fd, PPSETMODE, &mode); /*set the direction of transmission(reception in this case) */ ioctl(fd, PPDATADIR, &dir); /*read value from Control register */ ioctl(fd, PPRCONTROL, &ch); printf("Intial values of Control register is %d\n", ch); /*read value from Status register */ ioctl(fd, PPRSTATUS, &ch); printf("Intial value of status register is %d\n", ch); while(1){ printf("B4 read{");//before reading from data register /*read value from Status register */ ioctl(fd, PPRSTATUS, &ch); printf("Status->%d", ch); /*read value from Control register*/ ioctl(fd, PPRCONTROL, &ch); printf("Control->%d}\t",ch); /* READ the Sent Data from data register*/ ioctl(fd, PPRDATA, &buf); printf("Data->%c\t",buf); printf("After read{"); // after reading from data register /*read from Control register*/ ioctl(fd, PPRCONTROL, &ch); printf("Control->%d",ch); /*read from Status register*/ ioctl(fd, PPRSTATUS, &ch); printf("Status->%d}\n", ch); /*delay a bit*/ usleep(1000); } return 0; } /*END of CODE for receiving data*/ ------------SAMPLE OUTPUT------------- Intial values of Control register is 12 Intial value of status register is 127 B4 read{Status->127Control->12} Data->˙ After read{Control->12Status->127} B4 read{Status->127Control->12} Data->J After read{Control->12Status->127} B4 read{Status->127Control->12} Data->J After read{Control->12Status->127} B4 read{Status->127Control->12} Data->J After read{Control->12Status->127} B4 read{Status->127Control->12} Data->e After read{Control->12Status->127} B4 read{Status->127Control->12} Data->e After read{Control->12Status->127} B4 read{Status->127Control->12} Data->s After read{Control->12Status->127} B4 read{Status->127Control->12} Data->s After read{Control->12Status->127} B4 read{Status->127Control->12} Data->u After read{Control->12Status->127} B4 read{Status->127Control->12} Data->u After read{Control->12Status->127} B4 read{Status->127Control->12} Data->s After read{Control->12Status->127} B4 read{Status->127Control->12} Data->s After read{Control->12Status->127} B4 read{Status->127Control->12} Data->s After read{Control->12Status->127} B4 read{Status->127Control->12} Data->! After read{Control->12Status->127} B4 read{Status->127Control->12} Data->! After read{Control->12Status->127} ----------END of output--------------- Md.Zaheeruddin Khan |
![]() |
| Tags |
| parallel, port, programming |
| Thread Tools | |
| Display Modes | |
|
|