Ruby Serial Port for windows


#1

Hi,

Sort of new to Ruby and need help. I have been reading through all the
serial port related information that is available out there and have
come to a complete stop. I need to communicate with a device via my
laptop’s (Dell) serial port. I can do that via hyper terminal, python
and perl scrips. I have built a GUI using the wxruby and I need to be
able to use ruby to talk to the device. I have tried every thing from
simple to complex thread synchronization to be able to write and read
from serial port. In each technique the read gets hung up and after
termitaing the program I get this error: Exit code: -1073741510. I could
not build any of the serial port library out there i.e. win32Serial and
etc. I had success compiling all the libs with the ‘nmake /I’ option but
it won’t build the “.so” image and I don’t get any compiler error with
the ‘/I’ option. I am using ruby 1.8.6 and serialport.so image that I
downloaded. Any one has a functional snippet of a rs232 or serial port
communication code that I could use? I’d greatly appreciate the help!

Thanks!


#2

Riad Riad wrote:

Hi,

Sort of new to Ruby and need help. I have been reading through all the
serial port related information that is available out there and have

I’d greatly appreciate the help!

Thanks!
I noted someone had some success using eventmachine with it once.
Good luck!
-=R


#3

Any one has a functional snippet of a rs232 or serial port
communication code that I could use? I’d greatly appreciate the help!

Here’s some code I used to interface with a Druck barometer over rs232 :

class DruckInterface
require ‘Win32Serial’

def initialize
@port = Win32Serial.new
@port.open(“COM1”)
# 9600 baud / 8 bytesize / no parity / 1 stopbit
@port.config(9600, 8, Win32Serial::NOPARITY,
Win32Serial::ONESTOPBIT)
# optionally configure timeouts
@port.timeouts(0, 200, 0, 0, 0)
end

def read_pressure
@port.write(":UNIT MBAR;\r") # Switch measurement units to mBar
sleep(1)
@port.write(":SENS:PRES?;:UNIT?;\r")
response = @port.read(39)
@port.write(":UNIT PSI;\r") # Reset measurement units to PSI
@port.close

pressure_str,unit_str = response.split(';')
pressure = pressure_str.split[1].to_f
unit = unit_str.split[1].downcase

return "#{pressure} #{unit}"

end
end

I used the win32serial library here :
http://grub.ath.cx/win32serial/

which worked fine on my system (Windows XP sp3, using cygwin ruby, but I
think it’ll work with the one-click version of Ruby)

Hope this helps,

Chris


#4

Chris L. wrote:

I used the win32serial library here :
http://grub.ath.cx/win32serial/

which worked fine on my system (Windows XP sp3, using cygwin ruby, but I
think it’ll work with the one-click version of Ruby)

Hope this helps,

Chris

Thanks! But I can’t seem install this library. Following the readme I
was trying to build the library; the regular make give the following
error:
Makefile:127: *** target pattern contains no `%’. Stop.

The nmake give the following error:

Microsoft ® Program Maintenance Utility Version 8.00.50727.762
Copyright © Microsoft Corporation. All rights reserved.

    c:\Ruby\bin\ruby -e "puts 'EXPORTS', 'Init_Win32Serial'"  > 

Win32Serial-i386-mswin32.def
cl -nologo -I. -Ic:/Ruby/lib/ruby/1.8/i386-mswin32
-Ic:/Ruby/lib/ruby/1.8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -c
-Tcrb_serial_wrapper.c
NMAKE : fatal error U1077: ‘“c:\Program Files\Microsoft Visual Studio
8\VC\bin\cl.EXE”’ : return code ‘0xc0000135’
Stop.

nmake /I takes me this far apparently with no error:

Microsoft ® Program Maintenance Utility Version 8.00.50727.762
Copyright © Microsoft Corporation. All rights reserved.

    cl -nologo -I. -Ic:/Ruby/lib/ruby/1.8/i386-mswin32 

-Ic:/Ruby/lib/ruby/1.8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -c
-Tcrb_serial_wrapper.c
cl -nologo -I. -Ic:/Ruby/lib/ruby/1.8/i386-mswin32
-Ic:/Ruby/lib/ruby/1.8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -c
-Tcserial.c
cl -nologo -LD -FeWin32Serial.so rb_serial_wrapper.obj
serial.obj msvcrt-ruby18.lib oldnames.lib user32.lib advapi32.lib
shell32.lib ws2_32.lib -link -incremental:no -debug -opt:ref -opt:icf
-dll -libpath:"." -libpath:“c:/Ruby/lib”
-def:Win32Serial-i386-mswin32.def -implib:Win32Serial-i386-mswin32.lib
-pdb:Win32Serial-i386-mswin32.pdb

But nmake /I install gives me the following errors:

nmake /I install

Microsoft ® Program Maintenance Utility Version 8.00.50727.762
Copyright © Microsoft Corporation. All rights reserved.

    cl -nologo -I. -Ic:/Ruby/lib/ruby/1.8/i386-mswin32 

-Ic:/Ruby/lib/ruby/1.
8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -c -Tcrb_serial_wrapper.c
cl -nologo -I. -Ic:/Ruby/lib/ruby/1.8/i386-mswin32
-Ic:/Ruby/lib/ruby/1.
8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6 -c -Tcserial.c
cl -nologo -LD -FeWin32Serial.so rb_serial_wrapper.obj
serial.obj msvcrt
-ruby18.lib oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib
-link
-incremental:no -debug -opt:ref -opt:icf -dll -libpath:"."
-libpath:"c:/Ruby/lib
" -def:Win32Serial-i386-mswin32.def -implib:Win32Serial-i386-mswin32.lib
-pdb:Wi
n32Serial-i386-mswin32.pdb
c:/Ruby/lib/ruby/1.8/fileutils.rb:843:in stat': No such file or directory - Win 32Serial.so (Errno::ENOENT) from c:/Ruby/lib/ruby/1.8/fileutils.rb:843:ininstall’
from c:/Ruby/lib/ruby/1.8/fileutils.rb:1395:in
fu_each_src_dest' from c:/Ruby/lib/ruby/1.8/fileutils.rb:1409:infu_each_src_dest0’
from c:/Ruby/lib/ruby/1.8/fileutils.rb:1393:in
fu_each_src_dest' from c:/Ruby/lib/ruby/1.8/fileutils.rb:840:ininstall’
from c:/Ruby/lib/ruby/1.8/un.rb:183:in install' from c:/Ruby/lib/ruby/1.8/un.rb:55:insetup’
from c:/Ruby/lib/ruby/1.8/un.rb:178:in `install’
from -e:1
install -c -p -m 0755 Win32Serial.so
c:\Ruby\lib\ruby\site_ruby\1.8\i386-msvcrt

Any one else has encounter this issue? For now I have moved away from
Ruby and implemented my stuff using Python, pyserial and wxpython; that
works like a champ.

Thanks


#5

Daniel Malcolm Webb [dbw] wrote:

Can anyone explain why 1.9 isn’t being pushed as standard?

Because there’s no stable release of ruby 1.9 yet.

PS: Please don’t post your questions as replies to other posts which
have
nothing to do with yours.

HTH,
Sebastian


#6

By the looks of the Ruby-Lang site, 1.8.7 is still being pushed. Can
anyone explain why 1.9 isn’t being pushed as standard?

Cheers,

Dan