[LCP]reg serial communication in linux.

sowmya.k sowmi99 at yahoo.com
Tue Oct 14 17:31:09 UTC 2003


I had connected 2 systems using null modem
cable(RS232). 
My problem comes in the reading part.
My coding goes this way.
   First I had opened my tty (i.e my terminal screen
and keyboard)
   Then I set some parameters to it.
   Third I opened my port and finished all my
settings.
   Fourth I started to write and read datas from the
port.
   Atlast I closed everything.
 Let me give the code I used to read and write


To write datas to the port
  
     while (STOP==FALSE)   //STOP is defined to be
TRUE
      {
         status = fread(&Key,1,1,input);
         if (status==1)  //if a key was hit
         {
             fputc((int) Key,output);
             write(fd,&Key,1);          //write 1 byte
to the port
           }      
       }



To read from the port

         if (wait_flag==FALSE)  //if input is
available
         {
            res = read(fd,buf,255);
            if (res)
            {
               for (i=0; i<res; i++)  //for all chars
in string
               {
                  In1 = buf[i];
                  printf(message,"%c ",In1);
                        fputs(message,output);
                      }
                   }
            wait_flag = TRUE;      /* wait for new
input */
         }  //end if wait flag == FALSE

      }  //while stop==FALSE
      

Thanking you

sowmya

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com



More information about the linuxCprogramming mailing list