Hi All,
  I have written two simple applications for reading
and writing from the serial port.The problem is when I
open /dev/ttyS1 and do read/write I cant read from the
device whereas when I open /dev/ttyS0 and do
read/write then I can very well read the full ten
bytes sent to the port while writing or sometimes I
even get only 1 or 2 bytes read from the port.
Now most important thing is, /dev/ttyS0 is used by
mouse in my PC and /dev/ttyS1 is the free serial port
to which I have attached a loopback.
So using the loopback I cant read, whereas using the
mouse port I am sometimes successfull in reading.
Please chech out the attached files and help me
out.Thanks in advance.
Cheers 
Satya.


                                //      Writing.c
#include "stdio.h"
#include "string.h"
#include "sys/types.h"
#include "unistd.h"
#include "fcntl.h"
#include "errno.h"
#define DEVICE "/dev/trial1"

int main()
{
    int fd, iBytesWritten,i,j; /* file descriptor for
the device */
    char buff[10]; /* string of 10 bytes */
        
    if ((fd = open( DEVICE, O_WRONLY)) < 0 )
    {
        fprintf(stderr, "Can't open: ");
        perror(DEVICE);
        exit(1);
    } 
    else 
        printf("/dev/trial1  opened with fd=%d \n", fd);
        
      memset(buff,0,sizeof(buff));
        strcpy(buff,"JAIMATADI");
        buff[9]=0;
      
      iBytesWritten = write(fd,buff,sizeof(buff));
        printf("Number of bytes written %d\n",iBytesWritten);
        
      for (j=0; j<10000000;j++)
        continue;
        
    if (iBytesWritten < 0)
        printf("error number :  %d \n", errno);
        
        
        /* display the data written to the bufer */
        
      printf(" buff is: %s \n", buff);
        close(fd);
      return;
}
        
-------------------------------------------------------
                                        //Reading.c
#include "stdio.h"
#include "string.h"
#include "sys/types.h"
#include "unistd.h"
#include "fcntl.h"
#define DEVICE "/dev/trial1"

int main()
{
        int fd; /* file descriptor for the device */
        int i=0,iBytesread = 0;
        char buff[10]; /* string of 10 bytes */
        
   if ((fd = open( DEVICE, O_RDONLY)) < 0 ) 
   {
        fprintf(stderr, "Can't open: ");
        perror(DEVICE);
        exit(1);
    } 
   else 
      printf("/dev/trial1 opened with fd=%d \n", fd);
        
      memset(buff,0,sizeof(buff));
        
        iBytesread = read(fd,buff,sizeof(buff)); 
        
   if iBytesread == 0)
   {
        printf("%d bytes read\n",iBytesread);
        exit (1);
   }
   else 
   {
       /* display the data read into the bufer */
         
       printf("%d bytes read\n ",iBytesread); 
         printf(" buff is:  %s\n ", buff); 
         close(fd);
   }
}
        
--------------------------------------------------------




__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to