Sample Header Ad - 728x90

GTK app and serial port handlers

0 votes
1 answer
332 views
I’m writing a GTK C application for Linux OS on an embedded board. The first main window opens a serial (virtual) port for receive the data from a bar-code reader. I’m using standard open() function (inside my OpenPort() function). Then I call g_io_channel_new_file() and g_io_add_watch() to handle the rx signal. Do I really need the standard open() call? if (g_config.fdRfid==-1) g_config.fdRfid = OpenPort( g_config.portRfid, B115200); if (g_config.fdRfid!=-1) { ShowMainMessage(); GError *error = NULL; g_ioChannel = g_io_channel_new_file( g_config.portRfid, "r", &error); if (g_ioChannel) { guint source = g_io_add_watch( g_ioChannel, G_IO_IN | G_IO_PRI, serialRfidWatcher, &g_config); printf("> set watch ioCh: %p - source: %d\n", g_ioChannel, source); } else gtk_label_set_text( GTK_LABEL(g_labelMsg2), error->message); When I press a button I open a dialog child window: before that, I close the serial port by close() function and I disconnect the signal by g_io_channel_shutdown() function. The returned status is 1 = G_IO_STATUS_NORMAL. GIOStatus status = g_io_channel_shutdown( g_ioChannel, TRUE, NULL); g_io_channel_unref(g_ioChannel); if (g_config.fdRfid != -1) { ClosePort(&g_config.fdRfid); } Starting the dialog window I open again the same port (it is a window for test) and I reconnect the rx signal in the same previous way. Now if I read a bar-code in my debug output (by printf) I see that both signal handler of the main window and the handler in the dialog are called. Closing the dialog (closing the port and channel...) I return to main window. If I read a bar-code, three handler are fired, two on main window and one on the dialog. How can i disconnect the signal handlers? I think my way is incomplete .. Thanks!
Asked by SteMMo (197 rep)
Dec 16, 2022, 02:05 PM
Last activity: Dec 21, 2022, 11:39 AM