Re: Question about GTK+ and timers



Hi, Robert,

On Thu, Apr 7, 2011 at 12:59 AM, Robert Pearce <rob bdt-home demon co uk> wrote:
> Hi Igor,
>
> On Wed, 6 Apr 2011 22:38:43 -0700 you wrote:
>>
>> Just one question: AFAIU this pair is polling the port for data and
>> when they become available I need to
>> drop them in the GUI.
>> It's going to be something like MT, right?
>
> MT?
>
> It's not a threaded approach, if that's what you mean.
>
> Open the serial port and attach it to a g_io_channel:
>    fd = open ( "/dev/ttyS0", O_RDWR|O_NONBLOCK );
>    hFile = g_io_channel_unix_new ( fd );
>    g_io_channel_set_encoding ( hFile, NULL, &tErrPtr );
>
> Now you can hook up a call-back:
>    RxEventSrc = g_io_add_watch ( hFile, G_IO_IN, HandleAsyncRx, (gpointer)Instance );

But isn't it the same as registering the timer?

>
> Then in the call-back you read the incoming data and pass it to the GUI:
> gboolean HandleAsyncRx ( GIOChannel *source, GIOCondition condition,
>                                             gpointer data)
> {
>    GIOStatus stat;
>    gsize len;
>    GError * err = NULL;
>    unsigned char tmpbuf[32];
>
>    stat = g_io_channel_read_chars ( source,
>                                     (gchar*)tmpbuf, sizeof(tmpbuf), &len, &err );
>
>    // etc

And this is done the same way as the timer: it creates thread and
performs this function in it, right?

Thank you.

>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>


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