Page 1 of 1

Processing.org starter pack

Posted: Wed Mar 30, 2011 9:51 am
by tom
I used the simple project VB that was posted here about a year back so much that i decided to upload a simple project for processing. To get those that are interested started. This project sets up a telnet connection with an OLE or console, (change ip for console). Then it has a mousePressed event that sends a command to the palette software. The command is a HC.GetCurrentSelection() which then prints the return data in the console of processing.

install processing from processing.org. This setup should work on OSX as well as windows.

Start a new sketch. Save the file as "starter.pde". Then add a tab called "hc".
add to starter.pde

Code: Select all

//strand palette connection

void setup() {
  horizonConnect();
}

void draw(){
  horizonRead();
}

void mousePressed(){
  horizonWrite(send);
}
add to hc.pde

Code: Select all

/**
 * SIMPLE TELNET CLIENT for horizon control (strand palette)
 * connects to port 11123
 * sends string values to println
 */

//AVAILABLE COMMANDS
//horizonConnect() - call to make connection
//horizonRead() - read messages from HC
//horizonWrite(s) - write string to HC, use "print(HC.*())" to query a value

import processing.net.Client; //to setup connection
Client horizon; //declare client "horizon"

String dataIn; //return data
String dataOut =  "print(HC.GetCurrentSelectionSet(','))"; 
String endLine = "\r";
String send = dataOut + endLine;
String test;

//COMMANDS
void horizonConnect(){
  horizon = new Client(this, "127.0.0.1", 11123); // Connect to server on port 11123
}
void horizonRead() {
  if (horizon.available() > 0) { // If there's incoming data from the client...
    dataIn = horizon.readString(); // ...then grab it and print it
    println(dataIn.replace("\nHC>","")); //removes new line and HC> print string
  }
}
void horizonWrite(String s){
  horizon.write(s); //write line 
  horizonRead();
}