Search This Blog

May 16, 2012

Ruby access UART under Windows7

1. Download DevKit-tdm-32-4.5.2-20111229-1559-sfx and rubyinstaller-1.9.3-p125.exe

Install Ruby first.

2. Install DevKit
a. $cd
b. $ruby dk.rb init.
c. $ruby dk.rb review
d. $ruby dk.rb install

3. Test Installation
Confirm your Ruby environment is correctly using the DevKit by running
"$gem install rdiscount --platform=ruby". RDiscount should install correctly
and you should see "Temporarily enhancing PATH to include DevKit..." in the screen
messages. Next run $ruby -rubygems -e "require 'rdiscount'; puts'**Hello RubyInstaller**').to_html"
to confirm that the rdiscount gem is working.

4. Install serial port gem
$ gem sources -a
$ gem install serialport

5. Get serialport document

6. Test device board uart function   
Prepare one MCU card, download firmware with UART example code.
it will send back characters come from PC uart console. Use Putty
test uart, it works.

7. Write ruby uart test code.
require "serialport"

port_str = 3 
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

sp =, baud_rate, data_bits, stop_bits, parity)

#just read forever
while true do
  printf("%c", sp.getc)

8. Test ruby uart function
$ ruby uart.rb
it works.
We are done.

No comments: