From: Chris Lowis Date: 2008-12-08T20:31:02+09:00 Subject: Re: Ruby Serial Port for windows > 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 -- Posted via http://www.ruby-forum.com/.