Products for USB Sensing and Control
It is currently Tue May 21, 2013 4:20 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Support in Ruby?
PostPosted: Fri Apr 07, 2006 2:25 pm 
Offline
Fresh meat

Joined: Thu Apr 06, 2006 1:34 pm
Posts: 1
While the Python interface is very interesting (that is, I would use it if available any time soon), I am wondering if anyone might be working on something similar in Ruby?

Getting out of the compile->link-> run game would be great and even better if it could be in Ruby.


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 1:46 pm 
I too would be interested. In fact, I would be interested in working on something like this but need to be pointed in the right direction.

Developer(s), could you give me a quick rundown of what would be required to write something like this, based on your experience with the python libs?

Chad


Top
  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 5:29 am 
Offline
Phidget Mastermind

Joined: Tue Feb 07, 2006 5:16 am
Posts: 102
Location: Northwest UK
You need a means of interfacing from Ruby to arbitrary C library files. Python has a module called ctypes which lets you open the libphidget21.so library and call functions from it. You can also open phidget21.dll if running under Windows. That way you can write cross-platform code.

If Ruby supports such an interface, and also supports multi-threading, it should be fairly straightforward. If not, I reckon it would present quite a challenge.

As a matter of interest, does Ruby support an interactive command line environment? This was one of the big attractions of interfacing Python to Phidgets: I find command line tools extremely useful in devolping and testing hardware and software, and none of the officially-supported languages provide this. You could, of course, write your own command line interpreter, but it struck me as easier to interface the Phidgets library to a pre-existing language.

I have had very good results with Python, especially with the new version of the Linux library. However I only have a few Phidgets. To provide general support for any of these languages would obviously involve buying all the available Phidgets! That is really the biggest obstacle to providing anything that might be of use to others.


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 9:54 am 
Offline
Fresh meat

Joined: Fri Mar 02, 2007 9:46 am
Posts: 1
I wrote a very very simple Ruby C extension to the RFID reader that uses libphidgets. It is still pretty basic though, but it can print out the RFID tags.


Top
 Profile Send private message  
 
 Post subject: ruby
PostPosted: Thu Sep 27, 2007 9:42 am 
Offline
Fresh meat

Joined: Mon Sep 25, 2006 3:32 pm
Posts: 1
Would you be willing to send me how you connected to a phidget with ruby?


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Sun Apr 06, 2008 6:01 pm 
Offline
Fresh meat

Joined: Sun Apr 06, 2008 5:48 pm
Posts: 3
Hi,

I'm new to Phidgets and very interrested by there possibilities,
and so, having Ruby bindings would be great !
Ruby is a very modern language, OO, easy of use, pleasant to write.. Plus with Ruby on Rails it provides a very good web framework.
To answer to a question above, yes it has an Interactive Interpreter, and a very powerful one.
I don't know how is done interfacing with C, but ruby already has lots of bindings for lots of libraries, so I think there is an easy way to do.
So, once again,
Please give us some Ruby Bindings !


Top
 Profile  
 
 Post subject: How about using JRuby?
PostPosted: Mon Jun 09, 2008 11:30 pm 
Offline
Phidgetsian

Joined: Mon Dec 04, 2006 8:36 am
Posts: 11
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


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 8:05 am 
Offline
Fresh meat

Joined: Sun Apr 06, 2008 5:48 pm
Posts: 3
Thanks, looks interesting. Do you know if it's compatible with Ruby on Rails ?
I found an useful article how to extend Ruby with C there :
http://www.onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 11:15 pm 
Offline
Phidgetsian

Joined: Mon Dec 04, 2006 8:36 am
Posts: 11
Well, it would be "compatible" if you were running RoR via JRuby in the JVM. ;)


Top
 Profile Send private message  
 
PostPosted: Thu Jan 22, 2009 3:38 pm 
Offline
Phidgetsian

Joined: Mon Dec 04, 2006 8:36 am
Posts: 11
So, I am half-considering getting the phidget library embedded as a c-extension - and more importantly a gem installable library. Looking at the number of views on this thread I'm guessing there are a few folks coming here looking for a Ruby-based means for interacting with Phidgets.

Let me know if anyone is really interested in this and getting 'er done in community-based fashion.

Kit

kitplummer@gmail.com


Top
 Profile Send private message  
 
 Post subject: Re: Support in Ruby?
PostPosted: Sat Apr 25, 2009 6:26 am 
Offline
Fresh meat

Joined: Fri Apr 24, 2009 9:37 pm
Posts: 3
I just released a phidgets gem on RubyForge. It uses DL to call the C functions in the Phidgets shared library, so that will need to be installed for it to work. I have tested it on both Linux and Windows. At this point I have only implemented the Interface Kit and RFID classes because I don't actually have any other phidgets to test it with, so any help with implementing/testing other classes would be appreciated. I have tried to make it as easy as possible to add new classes by putting as much as possible into the Common class (from which the specific phidget classes are derived). I will try to add some documentation in the next couple weeks.

To install just run "gem install phidgets".

Here is an example of how to use it:

Code:
require 'rubygems'
require 'phidgets'

begin
  ik = Phidgets::InterfaceKit.new(-1,2000)

  puts "Device Name     = #{ik.getDeviceName}"
  puts "Serial Number   = #{ik.getSerialNumber}"
  puts "Device Version  = #{ik.getDeviceVersion}"

  ik.close

rescue Phidgets::Exception => e
  puts "Phidgets Error (#{e.code}). #{e}"

end


Top
 Profile Send private message  
 
 Post subject: Re: Support in Ruby?
PostPosted: Sun Aug 09, 2009 12:26 pm 
Offline
Fresh meat

Joined: Sun Apr 06, 2008 5:48 pm
Posts: 3
csdehaan wrote:
I just released a phidgets gem on RubyForge.

To install just run "gem install phidgets".


Any news from these bindings ?


Top
 Profile  
 
 Post subject: Re: Support in Ruby?
PostPosted: Wed Oct 28, 2009 10:10 am 
Offline
Phidgetsian

Joined: Mon Dec 04, 2006 8:36 am
Posts: 11
csdehaan wrote:
I just released a phidgets gem on RubyForge. It uses DL to call the C functions in the Phidgets shared library, so that will need to be installed for it to work. I have tested it on both Linux and Windows. At this point I have only implemented the Interface Kit and RFID classes because I don't actually have any other phidgets to test it with, so any help with implementing/testing other classes would be appreciated. I have tried to make it as easy as possible to add new classes by putting as much as possible into the Common class (from which the specific phidget classes are derived). I will try to add some documentation in the next couple weeks.

To install just run "gem install phidgets".

Here is an example of how to use it:

Code:
require 'rubygems'
require 'phidgets'

begin
  ik = Phidgets::InterfaceKit.new(-1,2000)

  puts "Device Name     = #{ik.getDeviceName}"
  puts "Serial Number   = #{ik.getSerialNumber}"
  puts "Device Version  = #{ik.getDeviceVersion}"

  ik.close

rescue Phidgets::Exception => e
  puts "Phidgets Error (#{e.code}). #{e}"

end


Any chance you'd be willing to share your code?


Top
 Profile Send private message  
 
 Post subject: Re: Support in Ruby?
PostPosted: Mon Nov 09, 2009 11:16 pm 
Offline
Phidgetsian

Joined: Mon Nov 09, 2009 10:37 pm
Posts: 6
Just tested the Phidgets Ruby Gem with the 0/0/4 InterfaceKit.
Works great. Thanks csdehaan!

If you are using the windows ruby installer, make sure when you install ruby to select the Enable RubyGems option in the component selection box. I must have forgot that when I installed my previous ruby build.


Top
 Profile Send private message  
 
 Post subject: Re: Support in Ruby?
PostPosted: Wed May 12, 2010 3:20 pm 
Offline
Fresh meat

Joined: Fri Apr 24, 2009 9:37 pm
Posts: 3
kitplummer wrote:
csdehaan wrote:
I just released a phidgets gem on RubyForge. It uses DL to call the C functions in the Phidgets shared library, so that will need to be installed for it to work. I have tested it on both Linux and Windows. At this point I have only implemented the Interface Kit and RFID classes because I don't actually have any other phidgets to test it with, so any help with implementing/testing other classes would be appreciated. I have tried to make it as easy as possible to add new classes by putting as much as possible into the Common class (from which the specific phidget classes are derived). I will try to add some documentation in the next couple weeks.

To install just run "gem install phidgets".

Here is an example of how to use it:

Code:
require 'rubygems'
require 'phidgets'

begin
  ik = Phidgets::InterfaceKit.new(-1,2000)

  puts "Device Name     = #{ik.getDeviceName}"
  puts "Serial Number   = #{ik.getSerialNumber}"
  puts "Device Version  = #{ik.getDeviceVersion}"

  ik.close

rescue Phidgets::Exception => e
  puts "Phidgets Error (#{e.code}). #{e}"

end


Any chance you'd be willing to share your code?


Yes. The code is on RubyForge and is released under the GPL. The project name is phidgets.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group