Greetings All:
I'm having problems acking data from a serial port and having the new data generate a gtk event so my data is displayed. I have one gtk entry per serial port configured thusly.
Code:
ports->serial_port[channel].data_text = gtk_text_buffer_new(NULL);
ports->serial_port[channel].data_dialog = gtk_text_view_new_with_buffer(ports->serial_port[channel].data_text);
ports->serial_port[channel].data_text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ports->serial_port[channel].data_dialog));
Each open port receives a thread that uses a blocking read thusly.
Code:
ports->serial_port[channel].thread_i_ret =
pthread_create(&ports->serial_port[channel].thread_proc,
NULL,spawn_listen,(void*)ports);
That process looks like this.
Code:
pthread_mutex_lock(&ports->serial_port[channel].mutex);
bzero(ports->serial_port[channel].port_data,
sizeof(ports->serial_port[channel].port_data));
ports->serial_port[channel].data_length =
read(ports->serial_port[channel].chan,&ports->serial_port[channel].port_data,9);
sprintf(buffer,"%s",ports->serial_port[channel].port_data);
gtk_text_buffer_get_start_iter(ports->serial_port[channel].data_text,&start);
gtk_text_buffer_get_end_iter(ports->serial_port[channel].data_text,&end);
len = gtk_text_buffer_get_char_count(ports->serial_port[channel].data_text);
gtk_text_buffer_delete(ports->serial_port[channel].data_text,&start,&end);
gtk_text_buffer_set_text(ports->serial_port[channel].data_text,buffer,strlen(buffer));
The data arrives just fine from any number of ports, but unless I move the cursor over the gtk_entry, no data is displayed. So I tried running a gtk_main_itteration_do(TRUE) every 30 milliseconds. This gave me a more than acceptable refresh and a smooth display, however after some time, I think the iters of gtk main and each of the spawned processes collide and crash gtk main.
What am I missing? I don't think I should need to run the gtk_main_itteration_do polling callback. Why won't the act of using gtk_text_buffer_set_text generate the needed gtk event to cuase the GUI to update and display the new data?
Thanks for any help you can give!
gtk_n008