I just tested it to see if I could use JRuby to access the Java API. Works. I'd not really played with JRuby until now. It is messy for sure...but, If you just want to code in Ruby this'll get you there. Obviously, it does require JRuby and Java...which may be unavailable to you.
Here's some sample code I used to test it:
Code:
include Java
require 'phidget21.jar'
include_class Java::com.phidgets.ServoPhidget
include_class Java::com.phidgets.event.AttachListener
include_class Java::com.phidgets.event.AttachEvent
include_class Java::com.phidgets.PhidgetException
class ServoAttachListener
servo = ServoPhidget.new()
def attached(ae)
begin
puts "Getting Device Name..."
servo = ae.getSource()
puts "Device Name: " + servo.getDeviceName()
puts "Getting Servo Count..."
puts "Servo Count: " + servo.getMotorCount().to_s
puts "Getting Servo Max Position..."
puts "Position: " + servo.getPositionMax(0).to_s
puts "Getting Servo Min Position..."
puts "Position: " + servo.getPositionMin(0).to_s
puts "Setting Servo to Max Position..."
servo.setPosition(0, 232.0)
rescue PhidgetException => e
puts "Java or Ruby exception: #{e}"
raise
end
end
end
puts "Hello Phidget Servo"
servo = ServoPhidget.new()
attach_listener = ServoAttachListener.new()
servo.addAttachListener(attach_listener)
servo.openAny()
while true
end
puts "Goodbye Phidget Servo"
Depending on what you were trying to do it would probably be worth while building out the Java API to Ruby in whole. I just wanted to see if it would work.
Kit