Ruby-serialport on Win32

Hi group,

has anybody used the serial port library on a Win32 system?

I would like to, but don’t have a compiler installed on the system where
I’d like to use (and the other system I use isn’t Win32).

And if you did: What compiler did you use? How did you make it. (Please
note the pun :wink:

Happy rubying

Stephan

Stephan Kämper wrote:

Hi group,

has anybody used the serial port library on a Win32 system?

I would like to, but don’t have a compiler installed on the system where
I’d like to use (and the other system I use isn’t Win32).

And if you did: What compiler did you use? How did you make it. (Please
note the pun :wink:

Happy rubying

Stephan

I haven’t used it, though I found out yesterday that I may need to in
the near future. In any case, someone mentioned on the list a few months
ago that the MSVC compiler and related tools are available at:

http://www.winprog.org/tutorial/msvc.html

Hope it works out…

I compiled it with both cygwin and mingw.
The .so made with the latter could be used with the PragProg’s
single-click installer (the former was to be used with cygwin’s
ruby only). What I did was installing mingw, building Ruby with it (just
to get a valid rbconfig.rb), and then using the new ruby binary run
ruby extconf.rb
make
at this point you cannot ‘make install’ cause that would put the .so
in the wrong sitelibdir, so I just copied it by hand to the appropriate
place in c:\Ruby (where I had installed the one-click distro). Of course
you can always just modify $:.

One thing that confused me a bit is that in mingw’s version #read (for
the serial port object) was blocking whereas in cygwin it wasn’t. But I
should have used #sysread anyway.

···

On Wed, Feb 04, 2004 at 02:15:04AM +0900, Stephan Kämper wrote:

Hi group,

has anybody used the serial port library on a Win32 system?

I would like to, but don’t have a compiler installed on the system where
I’d like to use (and the other system I use isn’t Win32).

And if you did: What compiler did you use? How did you make it. (Please
note the pun :wink:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

We are Pentium of Borg. Division is futile. You will be approximated.
– seen in someone’s .signature

Hi all,

Mauricio, thanks for you answer!

Mauricio Fernández wrote:

ruby only). What I did was installing mingw, building Ruby with it (just

Did that too. Up to running “make install” in the ruby directory
everything went fine.
Anyway, I apparently made a mistake (I think) since I have to set some
include paths explicitly, since otherwise neither ‘mkmf’ nor ‘rbconfig’
are found. Any ideas? Is there anything special to running ‘make
install’ on MinGW that I missed?

to get a valid rbconfig.rb), and then using the new ruby binary run
ruby extconf.rb
make

I assume you’re running these inside the ruby-serialport directory.
Doing this I get:

$ <path_to_ruby>/ruby.exe -I <path_to_ruby>/lib -I <path_to_ruby>
extconf.rb
checking for OS… mingw
checking for termios.h… no

After that running ‘make’ doesn’t make much sense I think.
Where could/should I get ‘termios.h’ from? Why is it not found?
BTW, ‘termios.h’ in fact is not on the PC (and the only file referencing
it is serialport’s ‘extconf.rb’).

Any tips are greatly appreciated.

Happy rubying

Stephan

Hi,

At Thu, 5 Feb 2004 21:55:04 +0900,
Stephan Kämper wrote in [ruby-talk:91615]:

I assume you’re running these inside the ruby-serialport directory.
Doing this I get:

$ <path_to_ruby>/ruby.exe -I <path_to_ruby>/lib -I <path_to_ruby>
extconf.rb
checking for OS… mingw
checking for termios.h… no

After that running ‘make’ doesn’t make much sense I think.
Where could/should I get ‘termios.h’ from? Why is it not found?
BTW, ‘termios.h’ in fact is not on the PC (and the only file referencing
it is serialport’s ‘extconf.rb’).

mingw doesn’t have termios because it borrows the runtime
library from VC. ruby-serialport seems not to support mingw
yet.

— extconf.rb.orig 2003-02-14 04:54:47.000000000 +0900
+++ extconf.rb 2004-02-05 22:22:14.000000000 +0900
@@ -1,13 +1,10 @@
require ‘mkmf’

-printf("checking for OS… “)
-STDOUT.flush
-os = /-([a-z]+)/.match(RUBY_PLATFORM)[1]
-puts(os)
-$CFLAGS += " -D#{os}”

···

-if !(os == ‘mswin’ or os == ‘bccwin’)

  • exit(1) if not have_header(“termios.h”) or not have_header(“unistd.h”)
    +if respond_to?(:macro_defined?)
  • win32 = macro_defined?(“_WIN32”, “”)
    +else
  • win32 = /mingw|mswin|bccwin/ =~ RUBY_PLATFORM
    +end
    +if win32 or (have_header(“termios.h”) and have_header(“unistd.h”))
  • create_makefile(“serialport”)
    end

-create_makefile(“serialport”)
— serialport.c.orig 2003-02-14 04:55:48.000000000 +0900
+++ serialport.c 2004-02-05 22:22:05.000000000 +0900
@@ -43,5 +43,5 @@ static VALUE sRts, sDtr, sCts, sDsr, sDc

-#if defined(mswin) || defined(bccwin)
+#ifdef _WIN32

@@ -92,5 +92,5 @@ static VALUE sp_create(class, _port)
rb_secure(4);
OBJSETUP(sp, class, T_FILE);

  • MakeOpenFile(sp, fp);
  • MakeOpenFile((VALUE)sp, fp);

    switch(TYPE(_port)) {
    @@ -520,5 +520,5 @@ static VALUE sp_get_dtr(self)

-#else /* defined(mswin) || defined(bccwin) /
+#else /
_WIN32 */

@@ -589,5 +589,5 @@ static VALUE sp_create(class, _port)
rb_secure(4);
OBJSETUP(sp, class, T_FILE);

  • MakeOpenFile(sp, fp);
  • MakeOpenFile((VALUE)sp, fp);

    switch(TYPE(_port)) {
    @@ -1054,5 +1054,5 @@ static VALUE sp_get_dtr(self)

-#endif /* defined(mswin) || defined(bccwin) /
+#endif /
_WIN32 */

@@ -1193,5 +1193,5 @@ sp_signals(self)
get_line_signals(self, &ls);
hash = rb_hash_new();
-#if !(defined(mswin) || defined(bccwin))
+#ifndef _WIN32
rb_hash_aset(hash, sRts, INT2FIX(ls.rts));
rb_hash_aset(hash, sDtr, INT2FIX(ls.dtr));


Nobu Nakada

Did that too. Up to running “make install” in the ruby directory
everything went fine.
Anyway, I apparently made a mistake (I think) since I have to set some
include paths explicitly, since otherwise neither ‘mkmf’ nor ‘rbconfig’
are found. Any ideas? Is there anything special to running ‘make
install’ on MinGW that I missed?

I don’t know if that’s the reason, but I was running this all in MSYS
(just to keep it completely separated from cygwin so that I wouldn’t run
the wrong ruby binary). I only remember setting the PATH to
$prefix/bin/ruby ($prefix being where Ruby was installed).

I assume you’re running these inside the ruby-serialport directory.
Doing this I get:

$ <path_to_ruby>/ruby.exe -I <path_to_ruby>/lib -I <path_to_ruby>
extconf.rb
checking for OS… mingw
checking for termios.h… no

This might be included in MSYS, in case you haven’t installed it
already. It should be there since the machine I tested this on had no
other dev. tools (except cygwin’s env. which was completely separated)
and I had no problem compiling this AFAIR.

···

On Thu, Feb 05, 2004 at 09:55:04PM +0900, Stephan Kämper wrote:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux ext2fs has been stable for a long time, now it’s time to break it
– Linuxkongreß '95 in Berlin

Mauricio Fernández wrote:

···

On Thu, Feb 05, 2004 at 09:55:04PM +0900, Stephan Kämper wrote:

Did that too. Up to running “make install” in the ruby directory
everything went fine.
Anyway, I apparently made a mistake (I think) since I have to set some
include paths explicitly, since otherwise neither ‘mkmf’ nor ‘rbconfig’
are found. Any ideas? Is there anything special to running ‘make
install’ on MinGW that I missed?

I don’t know if that’s the reason, but I was running this all in MSYS
(just to keep it completely separated from cygwin so that I wouldn’t run
the wrong ruby binary). I only remember setting the PATH to
$prefix/bin/ruby ($prefix being where Ruby was installed).

I assume you’re running these inside the ruby-serialport directory.
Doing this I get:

$ <path_to_ruby>/ruby.exe -I <path_to_ruby>/lib -I <path_to_ruby>
extconf.rb
checking for OS… mingw
checking for termios.h… no

This might be included in MSYS, in case you haven’t installed it
already. It should be there since the machine I tested this on had no
other dev. tools (except cygwin’s env. which was completely separated)
and I had no problem compiling this AFAIR.

No, stock mingw/msys/msysdtk doesn’t include termios.h, so it’ll fail to
compile, exactly as above.

Hi all,

Mauricio Fernández wrote:

I don’t know if that’s the reason, but I was running this all in MSYS
(just to keep it completely separated from cygwin so that I wouldn’t run
the wrong ruby binary). I only remember setting the PATH to
$prefix/bin/ruby ($prefix being where Ruby was installed).

As I installed pretty much everything available on the MinGW download
site, it’s like Osuka mentioned in another postinG: There’s just no
termio.h in MinGW.

This might be included in MSYS, in case you haven’t installed it
already. It should be there since the machine I tested this on had no

I did install MSYS and the MSYSDTK as mentioned above. So I guess that
your MinGW gets termios.h from somewhere else, probably CygWin or
whatever other compiler you have installed (or available via environment
variables).

other dev. tools (except cygwin’s env. which was completely separated)
and I had no problem compiling this AFAIR.

Well, I’ll try get around with Nobu’s pathch (Thanks Nobu!) or try
CygWin then.

Guillaume (aka moumar), Alan (Stern) are your reading this, too?

Stephan

Hi,

···

nobu.nokada@softhome.net wrote:

Hi,
mingw doesn’t have termios because it borrows the runtime
library from VC. ruby-serialport seems not to support mingw
yet.

— extconf.rb.orig 2003-02-14 04:54:47.000000000 +0900
+++ extconf.rb 2004-02-05 22:22:14.000000000 +0900

8< snipped the patch

Thanks a lot Nobu. That did it. :slight_smile:

Happy rubying!

Stephan

This might be included in MSYS, in case you haven’t installed it
already. It should be there since the machine I tested this on had no

I did install MSYS and the MSYSDTK as mentioned above. So I guess that
your MinGW gets termios.h from somewhere else, probably CygWin or
whatever other compiler you have installed (or available via environment
variables).

The only compilers I had on that machine were Cygwin & MSYS, but I don’t think
Cygwin was ‘contaminating’ MSYS since I ran them separately (and were
not sharing ENV vars). Maybe I’m just being silly and it didn’t compile,
although I am positive I noticed the difference concerning #read;
actually because #read blocked on MSYS’ version and not on Cygwin I
thought that build was broken and used win32serial instead (actually
rewriting it & just copy-pasting the Win32 API calls). It was only later
that I realized I should have been using #sysread from the beginning.

other dev. tools (except cygwin’s env. which was completely separated)
and I had no problem compiling this AFAIR.

Well, I’ll try get around with Nobu’s pathch (Thanks Nobu!) or try
CygWin then.

If you compile with Cygwin you have to use Cygwin’s ruby too. I’d
consider that if you don’t need the extensions bundled with the single
click installer.

···

On Fri, Feb 06, 2004 at 06:45:04PM +0900, Stephan Kämper wrote:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

The most important design issue… is the fact that Linux is supposed to
be fun…
– Linus Torvalds at the First Dutch International Symposium on Linux