My First JRuby Bluetooth App

TV, Coke and a laptop, it is time to have fun with JRuby and Bluetooth! In Netbeans 6!

TV, Coke and a laptop, it is time to have fun!

We are always trying to integrate Marge (Java Bluetooth Framework)[2] with other things. If you remember, in a last post[3], JavaFX Script was used, now it's time for JRuby! May you don't know, JRuby is Java implementation of the Ruby programming language. I am not a Ruby expert, but I hope I can become, because I am enjoying the language so much. Actually, I enrolled in a pretty interesting free online course[4] by Satish Talim. If you enjoyed the content, be sure you join on March too!

Here we go, no more delays! The basic idea of this post is to show a simple sample application that inquiry for Bluetooth devices, but more than just creating the application, be aware of thinking in the possibilities you can have with JRuby.

Get marge-core in Marge repository[6] (you can use Netbeans to checkout from Subversion and generate a jar, because the last version is under development and was not launched yet, we are working on it :) ). Otherwise download the last launched version (0.4.0[7]) and fix the inquiry method.

Get a JSR 82 implementation, I have used Avetana[8] for Linux. I have explained it in another post, you can take a look here[9].

Add marge-core and Avetana. Right click in the project -> Properties -> Java and then add the jars in the JRuby classpath.

Add the following code into main.rb. The code is pretty intuitive, because Ruby is! It basically imports some Marge classes (that are going to use Avetana internally), defines a listener that will be called during the inquiry and will print all the devices found. Also, the inquiry will be started by the singleton DeviceDiscoverer.