Re: Question about GTK+ and timers

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?


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 );

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

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