Working with Java
This page describes how to establish an OSC connection with your Make Controller over Java using the JavaOSC library.
Introduction
The Java programming language allows for the easy creation of programs with GUI's (Graphical User Interfaces). Interface tasks such as mouse and keyboard tracking (both of which are great inputs for your Make projects) which are complicated in other languages, are simple in Java. If you are aiming to create a program that will communicate with your controller, and will look nice and be simple to use, then Java may be your best choice.
Step 1 - Requirements
You will need to have the Java SE Development Kit installed. The JDK is available at Sun's website: http://java.sun.com/javase/downloads/index.jsp.
You'll also need a Java IDE (Integrated Development Environment). An IDE is a program in which you will write your code, and it will help you debug, compile, and run your program for you. A great simple yet powerful, free IDE is JCreator LE, which is available at http://www.jcreator.com/. If JCreator doesnt suit your needs, there are other free, popular alternatives such as Eclipse and NetBeans.
Finally, you need to grab a copy of the free JavaOSC library, which can be downloaded here: http://www.illposed.com/software/javaosc.html. This is an extension for the standard Java library which will allow you to communicate with the controller via OSC.
Step 2 - Set up your coding environment
Make sure you have downloaded and installed the Java SDK and your IDE (see Step 1) and become familiar with how to create a project, write some code, and compile and run a program in your IDE of choice. When you download the JavaOSC library, save it to a location on your computer of your choice. Once you have created a new project in your IDE, you will have to configure it to work with JavaOSC. The following screenshots demonstrate how to do this in JCreator, although the steps are similar for most IDE's.
Select "Project Properties" from the "Projects" menu bar item:
Click on "New" under the "Required Libraries" tab:
Enter "JavaOSC" for the name, the click on Add>Add Archive:
Browse to the location where you extracted the JavaOSC files you downloaded, and select all three of the .jar files from the "lib" folder:
Now, just click "Open," then Ok in the "Set Library" dialog, and finally, make sure the "JavaOSC" box is ticked in the "Project Properties" dialog, and click Ok. You are now ready to start writing your code.
Step 3 - Configure your computer's network and connect it to the Make Controller.
In order to communicate with your Make Controller over OSC, you must establish a network connection between your computer and the controller. The easiest way to do this is to plug the controller directly in to your computer with an ethernet cord. This process is explained in detail on this page: http://makingthings.com/documentation/tutorial/direct-ethernet-communication/tutorial-all-pages. It is recommended that you still leave the controller plugged in via USB at the same time, as this is the easiest way to supply power to the controller, and it allows you to manipulate it using mchelper.
Step 4 - Write your code
You will have to make sure to import the JavaOSC libraries to any class file in which you will be sending or receiving messages to/from your controller:
| import com.illposed.osc.*; import com.illposed.osc.utility.*; import java.net.InetAddress; |
Now it's time to let your imagination run wild. The documentation for JavaOSC is provided with the downloaded and provides a detailed API of all classes and methods you need to use to send and receive messages.
Note that in order to send messages to the controller, you must specify it's address on the network and the port it is listening on. This information can be retreived under the "Summary" tab in mchelper. If you have not established a network connection with your controller, see step 3. The following sample class show how to establish a connection to a board with the address 192.168.0.236 on port 10,000 (these are standard, default values) and turn on the LED's:
|
import java.awt.*; import com.illposed.osc.*; public class MakeTest { |

