Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Quick and dirty serial port class written in Objective-C and easily accessible from MacRuby
Objective-C Ruby
branch: master
Failed to load latest commit information.
AnalogReadSerial Amended last commit
English.lproj
Serialport.xcodeproj Modernized project for Xcode 4.1 under OSX Lion
.gitignore Added Arduino example code and MacRuby simple script
Info.plist Added Arduino example code and MacRuby simple script
PBSerialPort.h
PBSerialPort.m Few adjustments before GitHub upload
README.markdown Added Arduino example code and MacRuby simple script
SPController.h Initial commit
SPController.m Initial commit
Serialport_Prefix.pch Initial commit
example_script.rb Added Arduino example code and MacRuby simple script
main.m Initial commit
test.rb
version.plist

README.markdown

PBSerialPort

A quick and dirty serialport class written in Objective-C and tuned to be used as MacRuby class.

Usage

Copy the build product PBSerialPort.bundle to your MacRuby project folder.

Using the example Arduino sketch provided in AnalogSerialRead, run the following code in MacRuby:

#!/usr/env macruby

require "./PBSerialPort.bundle"

sp = PBSerialPort.new
sp.port = "/dev/tty.usbmodem411"
sp.baud = 9600

running = true

# Install management of ctrl-C signal
Signal.trap("SIGINT") do
  running = false
end

sp.open
raise unless sp.isOpen
sleep 2 # Give Arduino time for booting

values = []
while running do
  (0..5).each do |pin|
    sp.writeChar pin.to_s
    values << sp.readLine.chomp
  end
  puts values * " "
  values.clear
  sleep 0.1
end

print "Closing serial port..."
sp.close
puts "done!"
Something went wrong with that request. Please try again.