RE: Hello and win32 g_io_channel help needed

2007-05-06 Thread Burke.Daniel
Thank you for the reply Rob,

I ended up re-structuring to do polling every 250ms with a timeout on my
reads of zero.  It actually works quite well and fit's in to the scope
of the project which is not real-time anyway (it is for debugging a
simple IO board).

Such a shame since the callbacks would have been so nice, but as they
say Dumb it down for the lowest common denominator  Interesting how
windows is always the lowest common denominator.

Regards,

Burkey


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Robert Pearce
Sent: Friday, 4 May 2007 18:05
To: gtk-list@gnome.org
Subject: Re: Hello and win32 g_io_channel help needed

On Fri, 4 May 2007 10:40:30 +1000
Burke.Daniel [EMAIL PROTECTED] wrote:
 
 I can easily achieve this under Linux with a little 
 re-organisation to separate out the platform specific 
 portions.
 
 Does anyone have a fairly straightforward approach to
 do the same under windows?  If I cannot add a watch to
 the serial port I am afraid I may have to either fake
 it with a poll?

Short answer - no.

Longer answer - the Windows serial port handling is ugly and painful,
and really seriously not designed for this. It assumes you'll be using
a separate thread for everything. But there is just about provision for
it. Polling is even worse, because Windows doesn't support anything
equivalent to the Unix select call.

Here are some extracts from the code I've used on Windows (using
Borland C++ Builder) with some sucess:

  CommsLink::CommsLink ( const char * port, int baud ) {
 DCB ioDCB;

 hFile = CreateFile ( port, GENERIC_READ | GENERIC_WRITE, 0,
  NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
  NULL );

 sReadOverlap.hEvent = 0;
 sReadOverlap.Offset = 0;
 sReadOverlap.OffsetHigh = 0;
 sWriteOverlap.hEvent = 0;
 sWriteOverlap.Offset = 0;
 sWriteOverlap.OffsetHigh = 0;

 if ( GetCommState ( hFile, ioDCB ) )
 {
// Set up appropriate attributes
ioDCB.BaudRate = baud;
ioDCB.ByteSize = 8;
ioDCB.Parity = NOPARITY;
ioDCB.StopBits = ONESTOPBIT;
ioDCB.fParity = false;
ioDCB.fBinary = true;
SetCommState ( hFile, ioDCB );
 }
 else
 {
CloseHandle ( hFile );
hFile = INVALID_HANDLE_VALUE;
return;
 }
  }


  VOID CALLBACK HandleAsyncRx ( DWORD error, DWORD NumBytes,
LPOVERLAPPED lpOverlapped ) {
 CommsLink * cml = (CommsLink*)lpOverlapped-hEvent;
 lpOverlapped-hEvent = 0;
 cml-HandleRXEvent ( error, NumBytes );
  }


  bool CommsLink::SetRXHandler ( CommsCallback * cb )
  {
 RxCallBack = cb;
 sReadOverlap.hEvent = (void*)this;
 ReadFileEx ( hFile, AsyncReadBuffer, 8, sReadOverlap,
  HandleAsyncRx );
 return true;// Should check something
  }


The problem is, Windows doesn't have the nice clean Gtk main loop to
poll for that event. So while the above has avoided needing a separate
thread, it doesn't work unless you have a timer tick regularly putting
your code into a suitable interruptible sleep state :

  void __fastcall TAppWindow::Timer1Timer(TObject *Sender)
  {
 if ( SleepEx ( 0, 1 ) != 0 )
 {
// There was an event, which means we received some data
etc..


I had this more-or-less working when my customer decided to use Linux.
The port to Gtk was much easier.

Cheers,
Rob
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Hello and win32 g_io_channel help needed

2007-05-04 Thread Robert Pearce
On Fri, 4 May 2007 10:40:30 +1000
Burke.Daniel [EMAIL PROTECTED] wrote:
 
 I can easily achieve this under Linux with a little 
 re-organisation to separate out the platform specific 
 portions.
 
 Does anyone have a fairly straightforward approach to
 do the same under windows?  If I cannot add a watch to
 the serial port I am afraid I may have to either fake
 it with a poll?

Short answer - no.

Longer answer - the Windows serial port handling is ugly and painful,
and really seriously not designed for this. It assumes you'll be using
a separate thread for everything. But there is just about provision for
it. Polling is even worse, because Windows doesn't support anything
equivalent to the Unix select call.

Here are some extracts from the code I've used on Windows (using
Borland C++ Builder) with some sucess:

  CommsLink::CommsLink ( const char * port, int baud ) {
 DCB ioDCB;

 hFile = CreateFile ( port, GENERIC_READ | GENERIC_WRITE, 0,
  NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED,
  NULL );

 sReadOverlap.hEvent = 0;
 sReadOverlap.Offset = 0;
 sReadOverlap.OffsetHigh = 0;
 sWriteOverlap.hEvent = 0;
 sWriteOverlap.Offset = 0;
 sWriteOverlap.OffsetHigh = 0;

 if ( GetCommState ( hFile, ioDCB ) )
 {
// Set up appropriate attributes
ioDCB.BaudRate = baud;
ioDCB.ByteSize = 8;
ioDCB.Parity = NOPARITY;
ioDCB.StopBits = ONESTOPBIT;
ioDCB.fParity = false;
ioDCB.fBinary = true;
SetCommState ( hFile, ioDCB );
 }
 else
 {
CloseHandle ( hFile );
hFile = INVALID_HANDLE_VALUE;
return;
 }
  }


  VOID CALLBACK HandleAsyncRx ( DWORD error, DWORD NumBytes,
LPOVERLAPPED lpOverlapped ) {
 CommsLink * cml = (CommsLink*)lpOverlapped-hEvent;
 lpOverlapped-hEvent = 0;
 cml-HandleRXEvent ( error, NumBytes );
  }


  bool CommsLink::SetRXHandler ( CommsCallback * cb )
  {
 RxCallBack = cb;
 sReadOverlap.hEvent = (void*)this;
 ReadFileEx ( hFile, AsyncReadBuffer, 8, sReadOverlap,
  HandleAsyncRx );
 return true;// Should check something
  }


The problem is, Windows doesn't have the nice clean Gtk main loop to
poll for that event. So while the above has avoided needing a separate
thread, it doesn't work unless you have a timer tick regularly putting
your code into a suitable interruptible sleep state :

  void __fastcall TAppWindow::Timer1Timer(TObject *Sender)
  {
 if ( SleepEx ( 0, 1 ) != 0 )
 {
// There was an event, which means we received some data
etc..


I had this more-or-less working when my customer decided to use Linux.
The port to Gtk was much easier.

Cheers,
Rob
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Re: Hello and win32 g_io_channel help needed

2007-05-03 Thread Chris Vine
On Thu, 2007-05-03 at 14:04 +1000, Burke.Daniel wrote:
 Hail!  I am new.. so gday to everyone here.

 I am after some assistance with getting my event-driven serial port
 input working on Windows.
 
 The project is a portable serial tool for internal use within our
 company, I am writing it using libglademm since I love C++ and am a
 big Gnome/GTK fan (my laptop being Ubuntu Gnome based)

 On Linux I am using open and termios to handle the serial port setup,
 finally returning a GIOChannel for monitoring and so far.. so good.
 However I am now trying to get the evil version of it running and am
 not so happy.  Here I am using CreateFile to open and configure my
 port, then use:

 m_PortDescriptor = _open_osfhandle((long)m_PortHandle, 0);
 
 channel = g_io_channel_unix_new(m_PortDescriptor);

 to get the channel.  Later on I use g_io_add_watch to setup a monitor
 which seems to compile and run ok, however when I send data using
 g_io_channel_write_chars it seems to crash and I also don’t seem to be
 receiving data (often resulting another application halt)

You mention that you are using Windows, so is there any reason why you
are calling g_io_channel_unix_new() instead of the
g_io_channel_win32_new*() functions to create the GIOChannel object?

Chris




___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


RE: Hello and win32 g_io_channel help needed

2007-05-03 Thread Burke.Daniel
Actually I changed it to use the win32 one but it behaves the same.

This seems to be a difficult one to answer, so far nobody has been able to even 
suggest anything.


-Original Message-
From: Chris Vine [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 3 May 2007 20:15
To: Burke.Daniel
Cc: gtk-list@gnome.org
Subject: Re: Hello and win32 g_io_channel help needed

On Thu, 2007-05-03 at 14:04 +1000, Burke.Daniel wrote:
 Hail!  I am new.. so gday to everyone here.

 I am after some assistance with getting my event-driven serial port
 input working on Windows.
 
 The project is a portable serial tool for internal use within our
 company, I am writing it using libglademm since I love C++ and am a
 big Gnome/GTK fan (my laptop being Ubuntu Gnome based)

 On Linux I am using open and termios to handle the serial port setup,
 finally returning a GIOChannel for monitoring and so far.. so good.
 However I am now trying to get the evil version of it running and am
 not so happy.  Here I am using CreateFile to open and configure my
 port, then use:

 m_PortDescriptor = _open_osfhandle((long)m_PortHandle, 0);
 
 channel = g_io_channel_unix_new(m_PortDescriptor);

 to get the channel.  Later on I use g_io_add_watch to setup a monitor
 which seems to compile and run ok, however when I send data using
 g_io_channel_write_chars it seems to crash and I also don’t seem to be
 receiving data (often resulting another application halt)

You mention that you are using Windows, so is there any reason why you
are calling g_io_channel_unix_new() instead of the
g_io_channel_win32_new*() functions to create the GIOChannel object?

Chris




___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


RE: Hello and win32 g_io_channel help needed

2007-05-03 Thread Burke.Daniel
Failing this method I am moving to have my platform specific code handle the 
send and receiving, however I would still really like to use some kind of a 
callback like g_io_add_watch.

I can easily achieve this under Linux with a little re-organisation to separate 
out the platform specific portions.

Does anyone have a fairly straightforward approach to do the same under 
windows?  If I cannot add a watch to the serial port I am afraid I may have to 
either fake it with a poll?

Regards,
Burkey


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Burke.Daniel
Sent: Friday, 4 May 2007 10:11
To: gtk-list@gnome.org
Subject: RE: Hello and win32 g_io_channel help needed

Actually I changed it to use the win32 one but it behaves the same.

This seems to be a difficult one to answer, so far nobody has been able to even 
suggest anything.


-Original Message-
From: Chris Vine [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 3 May 2007 20:15
To: Burke.Daniel
Cc: gtk-list@gnome.org
Subject: Re: Hello and win32 g_io_channel help needed

On Thu, 2007-05-03 at 14:04 +1000, Burke.Daniel wrote:
 Hail!  I am new.. so gday to everyone here.

 I am after some assistance with getting my event-driven serial port
 input working on Windows.
 
 The project is a portable serial tool for internal use within our
 company, I am writing it using libglademm since I love C++ and am a
 big Gnome/GTK fan (my laptop being Ubuntu Gnome based)

 On Linux I am using open and termios to handle the serial port setup,
 finally returning a GIOChannel for monitoring and so far.. so good.
 However I am now trying to get the evil version of it running and am
 not so happy.  Here I am using CreateFile to open and configure my
 port, then use:

 m_PortDescriptor = _open_osfhandle((long)m_PortHandle, 0);
 
 channel = g_io_channel_unix_new(m_PortDescriptor);

 to get the channel.  Later on I use g_io_add_watch to setup a monitor
 which seems to compile and run ok, however when I send data using
 g_io_channel_write_chars it seems to crash and I also don’t seem to be
 receiving data (often resulting another application halt)

You mention that you are using Windows, so is there any reason why you
are calling g_io_channel_unix_new() instead of the
g_io_channel_win32_new*() functions to create the GIOChannel object?

Chris




___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list
___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


Hello and win32 g_io_channel help needed

2007-05-02 Thread Burke.Daniel
Hail!  I am new.. so gday to everyone here.

 

I am after some assistance with getting my event-driven serial port
input working on Windows.

 

The project is a portable serial tool for internal use within our
company, I am writing it using libglademm since I love C++ and am a big
Gnome/GTK fan (my laptop being Ubuntu Gnome based)

 

On Linux I am using open and termios to handle the serial port setup,
finally returning a GIOChannel for monitoring and so far.. so good.
However I am now trying to get the evil version of it running and am not
so happy.  Here I am using CreateFile to open and configure my port,
then use:

 

m_PortDescriptor = _open_osfhandle((long)m_PortHandle, 0);

channel = g_io_channel_unix_new(m_PortDescriptor);

 

to get the channel.  Later on I use g_io_add_watch to setup a monitor
which seems to compile and run ok, however when I send data using
g_io_channel_write_chars it seems to crash and I also don't seem to be
receiving data (often resulting another application halt)

 

I am not a GTK expert (this is my first project in it) and would really
appreciate help since I want to promote using this sort of solution
internally as much as possible.

 

Kind regards,

 

Burkey

___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list


RE: Hello and win32 g_io_channel help needed

2007-05-02 Thread Burke.Daniel
Actually.. I have commented out the reading and my callback is called
very quickly whenever I drag the window around with my mouse, so I
really think there must be something wrong with the way I am getting a
file descriptor or something like that?

 

 



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Burke.Daniel
Sent: Thursday, 3 May 2007 14:04
To: gtk-list@gnome.org
Subject: Hello and win32 g_io_channel help needed

 

Hail!  I am new.. so gday to everyone here.

 

I am after some assistance with getting my event-driven serial port
input working on Windows.

 

The project is a portable serial tool for internal use within our
company, I am writing it using libglademm since I love C++ and am a big
Gnome/GTK fan (my laptop being Ubuntu Gnome based)

 

On Linux I am using open and termios to handle the serial port setup,
finally returning a GIOChannel for monitoring and so far.. so good.
However I am now trying to get the evil version of it running and am not
so happy.  Here I am using CreateFile to open and configure my port,
then use:

 

m_PortDescriptor = _open_osfhandle((long)m_PortHandle, 0);

channel = g_io_channel_unix_new(m_PortDescriptor);

 

to get the channel.  Later on I use g_io_add_watch to setup a monitor
which seems to compile and run ok, however when I send data using
g_io_channel_write_chars it seems to crash and I also don't seem to be
receiving data (often resulting another application halt)

 

I am not a GTK expert (this is my first project in it) and would really
appreciate help since I want to promote using this sort of solution
internally as much as possible.

 

Kind regards,

 

Burkey

___
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list