Re: Monitoring IO



Hello,

I'm writing a program like Hyperterminal to monitor serial ports, I first used the gtk_input_add() function 
(not add_full), but now I use a GIOChannel, here is my code :

GIOChannel *IO;

fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
IO = g_io_channel_unix_new(fd);
g_io_add_watch(IO, G_IO_IN, (GIOFunc)Lis_port, GTK_TEXT(Texte));

gboolean Lis_port(GIOChannel *IOCh, GIOCondition condition, gpointer text)
{
  guint bytes_read;
  static gchar c[1000];

  if(g_io_channel_read(IOCh, c, 1000, &bytes_read) == G_IO_ERROR_NONE)
    {
      gtk_text_freeze(GTK_TEXT(text));
      gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, c, bytes_read);
      gtk_text_thaw(GTK_TEXT(text));
    }
  else
    printf("Error\n");
  return TRUE;
}

Hope this helps !

Bye
Julien






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