Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3102
| From | Regis d'Aubarede <regis.aubarede@gmail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Let Ruby read the serial port |
| Date | 2011-04-18 09:26 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <7f7e324059eb3bbe4eb5e07ceac63ea2@ruby-forum.com> (permalink) |
| References | <1c3018ffaf2482d637183ffea57c2d54@ruby-forum.com> |
I use IronRuby :
require "mscorlib"
require "System.Windows.Forms"
def portConfigure(portName,bauds,bits,stop,parity)
@components = System::ComponentModel::Container.new()
@serialPort1 = System::IO::Ports::SerialPort.new(@components)
portName ||= "COM3"
bauds ||= "9600"
bits ||= "8"
stopBits ||= "1"
parity ||= "none"
#puts "Configure..."
@serialPort1.DtrEnable = true
@serialPort1.RtsEnable = true
@serialPort1.PortName = portName
@serialPort1.StopBits = stopBits.to_i
@serialPort1.BaudRate = bauds.to_i
@serialPort1.DataBits = bits.to_i
@serialPort1.Open()
@serialPort1.DataReceived do |sender, e|
buff = @serialPort1.ReadExisting()
scanner(buff)
end
end
def writeString(str)
buf = System::Text::Encoding.GetEncoding("ASCII").GetBytes(str)
size = buf.Length
@serialPort1.Write(buf, 0, size)
end
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
Let Ruby read the serial port "Superpelican X." <superpelican12@gmail.com> - 2011-04-16 07:58 -0500
Re: Let Ruby read the serial port Brian Candler <b.candler@pobox.com> - 2011-04-16 16:14 -0500
Re: Let Ruby read the serial port andrew mcelroy <sophrinix@gmail.com> - 2011-04-16 16:38 -0500
Re: Let Ruby read the serial port Josh Cheek <josh.cheek@gmail.com> - 2011-04-16 17:03 -0500
Re: Let Ruby read the serial port Regis d'Aubarede <regis.aubarede@gmail.com> - 2011-04-18 09:26 -0500
csiph-web