IO fails




I have desperately tried to open and close COM-port by following ways:

guint sourceid;
gint fd; /* file descriptor for channel */

void
on_monitor_start_clicked               (GtkButton       *button,
                                        gpointer         user_data)
{

  fd = open (comport, O_RDWR, 0);

  if (fd == -1) {

    print_to_statusbar( tmp, "Failed to open COM-port for connections");
  } else {

    sourceid = gdk_input_add ( fd, GDK_INPUT_READ, &input_callback, NULL)
  }
}

void
on_monitor_stop_clicked                (GtkButton       *button,
                                        gpointer         user_data)
{


  gdk_input_remove(sourceid);

  if (close( fd ) == -1) {
      print_to_statusbar(tmp, "Closing COM-port failed");
  } else {
      print_to_statusbar(tmp, "Stopped writing data to COM-port");
  }
}


Every time function close is called, the system crashes. The same is when
I use IO-channels the same way. I'm testing the system using gtk4win and
wglade.

I've noticed that the reason is "input watcher", which in both cases does
something that causes close to fail. Why??? I also noticed strange thing,
that when using close (fd+1), system seems to work (re-open comport). So,
does anyone know what might be the reason? Also it would be nice to know
the meaning of reference counting (found in manuals ie.
http://developer.gnome.org/doc/API/2.0/glib/glib-io-channels.html#g-io-channel-unix-new
)

Also it would be nice to know how to open com-port in windows using IO
channels. Somewhere I saw mentioning about that g_io_channel_unix_new
works only with UNIX-systems and only partially with windows.


____________________________________


      Matti Sipilä

  matti sipila iki fi
____________________________________



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