Quick and dirty serial port class written in Objective-C and easily accessible from MacRuby
Objective-C Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
AnalogReadSerial
English.lproj
Serialport.xcodeproj
.gitignore
Info.plist
PBSerialPort.h
PBSerialPort.m
README.markdown
SPController.h
SPController.m
Serialport_Prefix.pch
example_script.rb
main.m
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!"