termios and gtkTextView



Greetings. 
 
 I am trying to receive input from a device connected to the serial port (/dev/ttyS0) and display it on the 
gtkTextView widget. However it sometimes hangs and from using GDB i can say it has something to do with 
pthreads. I however am not explicitly using threads for my program. Do i need GAsyncQueue for this? my code:
 
 in main():
     saio1.sa_handler = IOhandler1;
           sigemptyset(&saio1.sa_mask);
           saio1.sa_flags = 0; 
           saio1.sa_restorer = NULL;
           sigaction(SIGIO,&saio1,NULL);
 
           fcntl(fd1, F_SETOWN, getpid())    ; //which PID monitors 'in' signal
           fcntl(fd1, F_SETFL, FASYNC)    ; //0 || FASYNC
           tcgetattr(fd1,&oldtio1); // save current port settings 
 
 
           newtio1.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
     newtio1.c_iflag = IGNPAR  | IGNBRK; 
           newtio1.c_oflag = 0;
           newtio1.c_lflag = IEXTEN | ISIG; //technically for terminal so wont make a dif I think.       
           newtio1.c_cc[VMIN]=1;
           newtio1.c_cc[VTIME]=0;
     tcflush(fd1, TCIOFLUSH); //clears lines
           tcsetattr(fd1,TCSANOW,&newtio1);
 
 
 
 void IOhandler1 ()
 {
 
   gchar buf1[MYBUFSIZE];    
   res1 = read(fd1,buf1,MYBUFSIZE-1);
   gchar *utfedChar; 
   gint charCntr;
   gsize utfedSize;
 
   GtkTextIter startIter1;
   GtkTextIter endIter1;
 
 
   if (res1>0){ //if actualy GOT input - not necessary but double check.
      /*** sleep time required between read to buffer and write from buffer ***/
     usleep(10000); 
 
     for(charCntr=0 ; charCntr<res1 ; charCntr++){
     utfedChar = g_locale_to_utf8 (&buf1[charCntr], 1, &utfedSize, NULL, NULL);
 
     if (utfedChar==NULL || strcmp(utfedChar, "\x0D")==0){ 
         //ignore if character = \x00 /NULL or CR. Gotta replace with other chars here 
         ;
     }
     else {
         g_print("%s", utfedChar);
         gtk_text_buffer_get_bounds (buffer1, &startIter1, &endIter1);
         gtk_text_buffer_insert (GTK_TEXT_BUFFER(buffer1), &endIter1, utfedChar, utfedSize);
     }
     }  //end for
   }  //end if res1>0
 
   g_free (utfedChar);
   tcflush(fd1, TCOFLUSH); //clears lines
 }
 
 
 Thx.
 Alvin
 

                
---------------------------------
Yahoo! Photos ? Showcase holiday pictures in hardcover
 Photo Books. You design it and we?ll bind it!


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]