[#35036] Intentional Programming — "John" <nojgoalbyspam@...>

Hi all

17 messages 2002/03/01

[#35112] RDoc question — Michael Davis <mdavis@...>

I have a question about RDoc. I would like to reference an external

17 messages 2002/03/02

[#35162] string to array and back — Ron Jeffries <ronjeffries@...>

I am needing to convert strings to arrays of bytes and back. I see pack and

19 messages 2002/03/03

[#35364] file reading impossibly slow? — Ron Jeffries <ronjeffries@...>

So I'm doing this benchmark to work with my set program. Part of the problem is

18 messages 2002/03/07

[#35429] Interesting link on static/dynamic typing... — Robert Feldt <feldt@...>

...relevant to Ruby compared to other languages discussion:

25 messages 2002/03/08
[#35441] Re: Interesting link on static/dynamic typing... — Paul Brannan <paul@...> 2002/03/08

On Fri, Mar 08, 2002 at 05:34:43PM +0900, Robert Feldt wrote:

[#35460] Spam, ruby-talk, and me — Dave Thomas <Dave@...>

14 messages 2002/03/08

[#35537] Confusion — David Corbin <dcorbin@...>

The following is from my debugging through xmlc.rb

16 messages 2002/03/10

[#35579] RE: WIN32OLE and LDAP — "Morris, Chris" <chris.morris@...>

> The new version 0.4.2 of Win32OLE has WIN32OLE.bind method.

16 messages 2002/03/11

[#35652] Method type 'abstract' — Peter Hickman <peter@...>

The one thing I miss in Ruby is the abstract class method to go along

15 messages 2002/03/12

[#35653] Some potential RCRs — "Bob Alexander" <bobalex@...>

Here are a few thing I am considering submitting as RCRs. I'm looking =

50 messages 2002/03/12
[#35672] Re: Some potential RCRs — matz@... (Yukihiro Matsumoto) 2002/03/12

Hi,

[#35683] Re: Some potential RCRs — Massimiliano Mirra <list@...> 2002/03/12

On Wed, Mar 13, 2002 at 03:58:01AM +0900, Yukihiro Matsumoto wrote:

[#35697] Re: Some potential RCRs — David Alan Black <dblack@...> 2002/03/13

Hello --

[#35694] rpkg 0.3 — Massimiliano Mirra <list@...>

14 messages 2002/03/13
[#35699] RE: [ANN] rpkg 0.3 — <james@...> 2002/03/13

>

[#35787] testunit - setup -> set_up ? — "Morris, Chris" <chris.morris@...>

I'm just starting to use testunit instead of rubyunit ... I noticed with an

21 messages 2002/03/13
[#35793] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

Morris, Chris [mailto:chris.morris@snelling.com] wrote:

[#35796] Re: testunit - setup -> set_up ? — Dave Thomas <Dave@...> 2002/03/13

"Nathaniel Talbott" <nathaniel@talbott.ws> writes:

[#35797] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

dave@thomases.com [mailto:dave@thomases.com] wrote:

[#35898] camelCase and underscore_style — "Morris, Chris" <chris.morris@...>

First, a question. If underscore_style is the Ruby norm for methods and the

20 messages 2002/03/15
[#35924] Re: camelCase and underscore_style — "Guy N. Hurst" <gnhurst@...> 2002/03/15

Phil Tomson wrote:

[#35930] RE: camelCase and underscore_style — "Nathaniel Talbott" <nathaniel@...> 2002/03/16

Guy N. Hurst [mailto:gnhurst@hurstlinks.com] wrote:

[#35989] ANN: Locana GUI and GUI Builder version 0.81 — Michael Davis <mdavis@...>

I am pleased to announce release 0.81 of Locana. Locana is a GUI

16 messages 2002/03/16

[#35992] XPath — Michael Schuerig <schuerig@...>

27 messages 2002/03/16

[#36034] Mini Rant: Indenting — Thomas Hurst <tom.hurst@...>

Why is it that I see *so* much code like:

14 messages 2002/03/17

[#36049] web templating for static sites? — Massimiliano Mirra <list@...>

I'm using the Template Toolkit for generating static web sites and I

42 messages 2002/03/17
[#36426] web standars (was: web templating for static sites?) — Tobias Reif <tobiasreif@...> 2002/03/20

Albert Wagner wrote:

[#36052] Xml Serialization for Ruby — "Chris Morris" <chrismo@...>

=Xml Serialization for Ruby

20 messages 2002/03/17
[#36059] Re: [ANN] Xml Serialization for Ruby — Massimiliano Mirra <list@...> 2002/03/17

On Mon, Mar 18, 2002 at 05:20:56AM +0900, Chris Morris wrote:

[#36067] eval/Module question — David Corbin <dcorbin@...>

If I have a String src that is similar to the following:

13 messages 2002/03/18

[#36157] Development of Windows version of Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

Now that we've dumped the cygwin requirement for the Windows version of

63 messages 2002/03/18
[#36330] Re: Development of Windows version of Ruby — Ron Jeffries <ronjeffries@...> 2002/03/19

On Tue, 19 Mar 2002 14:05:27 GMT, "Albert L. Wagner" <alwagner@uark.edu> wrote:

[#36431] Re: Development of Windows version of Ruby — Dennis Newbold <dennisn@...> 2002/03/20

[#36458] Windows version of Ruby (proposals) — ptkwt@... (Phil Tomson) 2002/03/21

Dennis Newbold <dennisn@pe.net> wrote in message news:<Pine.GSO.3.96.1020320113603.22242B-100000@shell2>...

[#36482] RE: Windows version of Ruby (proposals) — "Christian Boos" <cboos@...> 2002/03/21

Some thoughts on the 2 first Windows issues, plus a 4th one...

[#36496] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

"Christian Boos" <cboos@bct-technology.com> writes:

[#36510] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36514] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

nobu.nokada@softhome.net writes:

[#36518] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36211] dots in Dir.entries — matz@... (Yukihiro Matsumoto)

Hi,

22 messages 2002/03/19

[#36231] style choice — Ron Jeffries <ronjeffries@...>

A style question for the community ... which of the following do you prefer, and

18 messages 2002/03/19

[#36345] ANN: REXML 2.0 — Sean Russell <ser@...>

I have a feeling there will only be three major revisions of REXML. Version

19 messages 2002/03/20

[#36610] Re: Windows version of Ruby (proposals) — Ron Jeffries <ronjeffries@...>

On Thu, 21 Mar 2002 14:11:55 GMT, Dave Thomas <Dave@PragmaticProgrammer.com> wrote:

16 messages 2002/03/22

[#36645] Ruby for Mac OS 10.1 — Jim Freeze <jim@...>

Hi:

28 messages 2002/03/23

[#36768] Re: Difference between 'do' and 'begin' — Clemens Hintze <c.hintze@...>

In <slrna9ulvi.f2h.mwg@fluffy.isd.dp.ua> Wladimir Mutel <mwg@fluffy.isd.dp.ua> writes:

23 messages 2002/03/26
[#36783] RE: Difference between 'do' and 'begin' — <james@...> 2002/03/26

[#36792] Re: Difference between 'do' and 'begin' — Kent Dahl <kentda@...> 2002/03/26

james@rubyxml.com wrote:

[#36808] Error calling Tk in a loop — <james@...>

I'm trying to write some code that pops up a Tk window when for certain

15 messages 2002/03/26

[#36841] RE: Windows version of Ruby (proposals) — "Andres Hidalgo" <sol123@...>

I believe that Ruby has a place in windows (Office), I happened to have

14 messages 2002/03/27

[#36863] Hash.new(Hash.new) doesn't use Hash.new as default value — "Jonas Delfs" <jonas@...>

Hi -

18 messages 2002/03/27

[#37080] Why isn't Math object-oriented? — Bil Kleb <W.L.Kleb@...>

So I'm reading along in the Pixaxe book (yet again), and I am told

15 messages 2002/03/30

[#37121] String#begins?(s) — timsuth@... (Tim Sutherland)

class String

24 messages 2002/03/31

RE: Ruby Serial Ports under Windows

From: "Allen J Mitchell" <ajm@...>
Date: 2002-03-07 03:43:28 UTC
List: ruby-talk #35355
David, I had the same need and have been using win32ole to access the mscomm
serial com object which comes with visual basic.

I am enclosing a copy of the code I wrote.... consider it an alpha, It's
almost midnight here so I will send an example of it's use tomorrow.  Please
do not put into general circulation yet, I need to spend some more time on
it.  Hope it helps... Let me know.

Ignore the PacketizeData class, I'm still working on that. :)

-----Original Message-----
From: David Wende [mailto:DWende@lynxpn.com]
Sent: Wednesday, March 06, 2002 11:38 AM
To: ruby-talk ML
Subject: Ruby Serial Ports under Windows


I've started using Ruby a week ago as my first OOP
language - very impressed.
I need to access the COM1 serial port under Windows.
Can this be done?

Thanks

David Wende

Attachments (1)

MScomm.rb (6.75 KB, text/x-ruby)
require 'win32ole'
require 'thread.rb'

class MSComm
  include WIN32OLE::VARIANT

	# Handshake Constants
	CONST_comNone				= 0 	# No handshaking.
	CONST_comXonXoff 			= 1 	# XOn/XOff handshaking.
	CONST_comRTS 				= 2 	# Request-to-send/clear-to-send handshaking.
	CONST_comRTSXOnXOff 		= 3 	# Both request-to-send and XOn/XOff handshaking.

	# OnComm Constants
	CONST_comEvSend 			= 1 	# Send event.
	CONST_comEvReceive 			= 2 	# Receive event.
	CONST_comEvCTS	 			= 3 	# Change in clear-to-send line.
	CONST_comEvDSR 				= 4 	# Change in data-set ready line.
	CONST_comEvCD 				= 5 	# Change in carrier detect line.
	CONST_comEvRing 			= 6 	# Ring detect.
	CONST_comEvEOF 				= 7 	# End of file.

	# Error Constants
	CONST_comEventBreak 		= 1001 	# Break signal received
	CONST_comEventFrame 		= 1004 	# Framing error
	CONST_comEventOverrun 		= 1006 	# Port overrun
	CONST_comEventRxOver 		= 1008 	# Receive buffer overflow
	CONST_comEventRxParity	 	= 1009 	# Parity error
	CONST_comEventTxFull 		= 1010 	# Transmit buffer full
	CONST_comEventDCB 			= 1011 	# Unexpected error retrieving Device Control Block (DCB) for the port

	# InputMode Constants
	CONST_comInputModeText 		= 0 	# (Default) Data is retrieved through the Input property as text.
	CONST_comInputModeBinary  	= 1 	# Data is retrieved through the Input property as binary data.

	@@clsid 	= "{648A5600-2C6E-101B-82B6-000000000014}"
	@@progid 	= "MSCOMMLib.MSComm"

	def initialize
		@dispatch 	= WIN32OLE.new @@progid
		@lastargs 	= nil
		@handlers   = {}
		@we         = nil
		@mutex		= Mutex.new
	end

	def AboutBox()
		ret = @dispatch._invoke(-552, [],[])
		@lastargs = WIN32OLE::ARGV
		ret
	end

	#----------------------------------------------------------
	# onEvent allows you to specify individual Proc routines
	# for events as specified above.
	# ie.
	# 	onEvent ( [MSComm::CONST_comEvReceive], Proc.new { | e, mscomm | print "Receive happened" }
	# 	onEvent ( [MSComm::CONST_comEvReceive,MSComm::CONST_comEvSend], Proc.new { | e, mscomm | print "Receive or send happened" }
	#
	# Note: that the proc must take a single argument which
	# is the MSComm object itself.
	#----------------------------------------------------------
	def onEvent ( eventList, handler = nil )
		raise "Invalid Event Array" if !eventList.kind_of?( Array )
		raise "Invalid Handler" if !( handler.nil? || handler.kind_of?( Proc ) )
		raise "Invalid Handler - should handle two arguments ( event, mscomm )." if handler.kind_of?( Proc ) && handler.arity != 2
		@mutex.synchronize do
			eventList.each { |e|
				@handlers[e] = handler
			}
		end
	end

	def CommPort
		@dispatch.CommPort
	end

	def baud
		@dispatch.Settings.split(",")[0]
	end

	def parity
		@dispatch.Settings.split(",")[1]
	end

	def dataBits
		@dispatch.Settings.split(",")[2]
	end

	def stopBits
		@dispatch.Settings.split(",")[3]
	end

	def Handshaking
		@dispatch.Handshaking
	end

	def Handshaking= ( hsMode )
		raise "Invalid handshaking value (#{hsMode})" if [CONST_comNone,CONST_comXonXoff,CONST_comRTS,CONST_comRTSXOnXOff].index( hsMode ) == nil
		@dispatch.Handshaking = hsMode
	end

	def RThreshold
		@dispatch.RThreshold
	end

	def RThreshold= ( numOfChars )
		@dispatch.RThreshold = numOfChars
	end

	def SThreshold
		@dispatch.SThreshold
	end

	def SThreshold= ( numOfChars )
		@dispatch.SThreshold = numOfChars
	end

	def open ( settings )
		close if self.PortOpen
		s = settings.split(":")
		s2 = s[1].split(",")
		# valid comm port?
		port = %w{ COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 COM10 COM11 COM12 COM13 COM14 COM15 COM16 }.index( s[0].upcase )
		raise "Invalid COM Port (#{s[0].upcase})" if port.nil?
		raise "Invalid Baud (#{s2[0].upcase})" if %w{ 110 300 600 1200 2400 9600 14400 19200 28800 38400 56000 128000 256000 }.index( s2[0].upcase ) == nil
		raise "Invalid Parity (#{s2[1].upcase})" if %w{ E M N O S }.index( s2[1].upcase ) == nil
		raise "Invalid Databits (#{s2[2].upcase})" if %w{ 4 5 6 7 8 }.index( s2[2].upcase ) == nil
		raise "Invalid Stopbits (#{s2[3].upcase})" if %w{ 1 1.5 2 }.index( s2[3].upcase ) == nil
		begin
	  		@dispatch.CommPort = port+1
			@dispatch.Settings = s[1]
			@dispatch.PortOpen = true
			@we = WIN32OLE_EVENT.new( @dispatch )
			@we.on_event { |*args| self.onEventHandler( *args ) }
			true
		rescue
			false
		end
	end

	def close
		@dispatch.PortOpen = false
		@we = nil
	end

	def Break
		@dispatch.Break
	end

	def Break= ( onOff )
		@dispatch.Break = onOff
	end

	def CommID
		@dispatch.CommID
	end

	def PortOpen
		@dispatch.PortOpen
	end

	def InBufferSize
		@dispatch.InBufferSize
	end

	def InBufferSize= ( size )
		@dispatch.InBufferSize = size
	end

	def InBufferCount
		@dispatch.InBufferCount
	end

	def Input
		@dispatch.Input
	end

	def Name
		@dispatch.Name
	end

	def InputLen
		@dispatch.InputLen
	end

	def InputLen= ( size )
		@dispatch.InputLen = size
	end

	def InputMode
		@dispatch.InputMode
	end

	def InputMode= ( mode )
		raise "Invalid input mode (#{mode})" if [CONST_comInputModeText,CONST_comInputModeBinary].index( mode ) == nil
		@dispatch.InputMode = mode
	end

	def setInputToText
		self.InputMode = CONST_comInputModeText
	end

	def setInputToBinary
		self.InputMode = CONST_comInputModeBinary
	end

	def isTextMode?
		self.InputMode == CONST_comInputModeText
	end

	def isBinaryMode?
		self.InputMode == CONST_comInputModeBinary
	end

	def Output= ( out )
		@dispatch.Output = out
	end

	def OutBufferCount
		@dispatch.OutBufferCount
	end

	def OutBufferSize
		@dispatch.OutBufferSize
	end

	def OutBufferSize= ( size )
		@dispatch.OutBufferSize = size
	end

	def CDHolding
		@dispatch.CDHolding
	end

	def CTSHolding
		@dispatch.CTSHolding
	end

	def DSRHolding
		@dispatch.DSRHolding
	end

	def DTREnable
		@dispatch.DTREnable
	end

	def DTREnable= ( onOff )
		@dispatch.DTREnable = onOff
	end

	def EOFEnable
		@dispatch.EOFEnable
	end

	def EOFEnable= ( onOff )
		@dispatch.EOFEnable = onOff
	end

	def RTSEnable
		@dispatch.RTSEnable
	end

	def RTSEnable= ( onOff )
		@dispatch.RTSEnable = onOff
	end

	def onEventHandler ( *args )
		raise "Invalid Event Notification #{args[0]}" if  args[0] != "OnComm"
		handler = nil
		e = @dispatch.CommEvent
		@mutex.synchronize do
			handler = @handlers[e]
			handler = @handlers["*"] if handler.nil?
		end
		handler.call( e, self ) if !handler.nil?
	end

end

class PacketizeData
	def initialize ( beginPacket, endPacket, onCompletePacket, onOutOfBoundsData )
		@bp 	= beginPacket
		@ep 	= endPacket
		@onCP 	= onCompletePacket
		@onOBD	= onOutOfBoundsData
		@data 	= ""
	end

	def clear
		@data = nil
	end

	def addData ( data )
		@data += data
		while ( @data.length )
			if ( @bp.nil? ) then
				#simply search for the end of the packet
				p = @data.index( @ep )
				if ( !p.nil? ) then
					@onCP.call( @data[0,p] )
					@data = @data[p+@ep.length,-1]
				else
					return
				end
			else
				# could be a partial match
			end
		end
	end

end

In This Thread