Hi,
You are still trying to use GTK+ in a busy loop, when you should be thinking in an event driven way.
Code:
#include <gtk/gtk.h>
void setup_serial_port()
{
/* set up the serial port */
}
void create_display_1(void)
{
/* create the user interface for display 1 and connect any signals for it */
}
void update_display_1(()
{
/* update display using data from serial port and return */
}
void create_display_2(void)
{
/* create the user interface for display 2 and connect any signals for it */
}
void update_display_2()
{
/* update display using data from serial port and return */
}
gboolean timer(gpointer data)
{
/* read data from serial port */
/* Your code here ............ */
/* How you transfer your data is up to you */
update_display_1();
update_display_2();
return TRUE;
}
int main (int argc, char *argv[])
{
gtk_init(&argc, &argv);
create_display_1();
create_display_2();
setup_serial_port();
/* set a timer to be called every 0.1s, but this can be set to any timeout */
g_timeout_add(100, timer, NULL);
/* Run until gtk_main_quit() is called */
gtk_main();
return 0;
}
This is an outline of an event driven GTK+ application.
Basically what it does is set up the user interfaces, connect the signals. It also sets up the serial port, and sets a timer that would be called every 0.1 seconds. The timeout callback would read from the serial port and then update the user interface (without needing to call gtk_main()).
The application then calls gtk_main(). This is where the application becomes alive. gtk_main() sits in its own special loop calling any callback that is connected. Such as button presses, menu selections, timeouts etc.... It also performs the displaying of the user interface.
In this case I have added a timeout which is called every 0.1 seconds. The callback function then reads the serial port and updates the user interface.
I do not know the data rate or what the data being read from the serial port is, so reading the serial every 0.1 seconds may well be too slow. You could increase the rate (this may slow down the user interface). Or you could add a different callback to gtk_main() which watches for any data on the serial port. This is a slightly more complex interface so ask once you have got to grips with event driven programming.
Your application only needs to have ONE gtk_main(), and certainly no busy loops trying to read data that is not there.
E.