We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
OSCP5 (Read 1912 times)
OSCP5
Feb 19th, 2007, 9:26am
 
Hi,  I'm having some trouble with this code I've written to send OSC messages to Supercollider and across a switch to two other machines.

1.  I can't seem to bind addresses or values to OSC messages at all.  You will notice in the routeData method i have place printlns to give me info on the contents of the message.  Those statements which return information from the message come back null and the statement which is supposed to return the value of the first argument in the message throws a nullPointer Exception.

2.  Im establishing connections across machines using OSCP5 TCP, however as soon as i connect from a client terminal which calls the routeData method i get an ArrayIndexOutOfBounds Exception at the server terminal.

Hope someone out there can help!
Thanks.

Code:

// Luke George
// 3rd Year Music Informatics Bsc
// January - March 2007

//Import necessary packages
import oscP5.*;
import netP5.*;

public class DataRouter extends Thread{

 //Create OSC supercollider client
 OscP5 scClient;

 //Create tcp server
 OscP5 server;

 //Create client A
 OscP5 clientA;

 //Create client B
 OscP5 clientB;

 //Create float arrays for data from remote locations
 float[] remoteData1, remoteData2;

 //Reference Strings for client addresses
 String clientAAddr, clientBAddr;

 //NetAddress object defining loopback for supercollider
 NetAddress loopBack;

 //Create bundle used to package data for remote locations
 OscBundle msgBundle;

 //Constructor
 public DataRouter(){

   //Call to superclass constructor
   super("DataRouter");

   // Local OSC traffic to SC goes via UDP
   scClient = new OscP5(this, 6969);

   //loopback address for Supercollider
   loopBack = new NetAddress("127.0.0.1", 57120);

   //Network OSC traffic travels by TCP
   server  = new OscP5(this, 5000, OscP5.TCP);

   //Initialise msgBundle
   msgBundle = new OscBundle();

   //Initialise data array and fill with 0s
   remoteData1 =  new float[3];    
   for(int i = 0; i < remoteData1.length; i = i + 1){
     remoteData1[i] = 0;
   }

   //Initialise data array and fill with 0s
   remoteData2 =  new float[3];
   for(int i = 0; i < remoteData1.length; i = i + 1){
     remoteData2[i] = 0;
   }

   //Start the Thread
   this.start();  

 }

 //boot sets up the client connections to the other machines.
 //This method is user triggered since servers must be running
 //on remote machines for connections to be established
 void boot(String clientAAddr, String clientBAddr){

   this.clientAAddr = clientAAddr;
   this.clientBAddr = clientBAddr;

   println();
   println("Booting...");

   //Attempt to create client connection A
   println();
   println("Contacting clientA: "+clientAAddr);
   clientA = new OscP5(this, clientAAddr, 5000, OscP5.TCP);
   delay(1000);

   //Attempt to create client connection B
   println();
   println("Contacting clientB: "+clientBAddr);
   clientB = new OscP5(this, clientBAddr, 5000, OscP5.TCP);
   delay(1000);
 }

 //Method used to route data locally (supercollider) and also to
 //remote locations.  Data arriving is immediately despatched via
 //OSC to supercollider locally.  Every third call, i.e. when
 //values for all 3 sensors are present a bundle is sent via OSC to
 //remote locations
 void routeData(float[] data){

   for(int i = 0; i < data.length; i = i + 1){
     String addr = "/sens"+i;
     println("Address: "+addr);
     float value = (0.5*data[i]) + (0.25*remoteData1[i]) + (0.25*remoteData2[i]);
     println("Value: "+value);
       OscMessage message = (addr);
     message.add(value);
     println("Address: "+message.address());
     println("Value: "+message.get(1).floatValue());  <<<< BOMBS OUT HERE
     scClient.send(message, loopBack);
     msgBundle.add(message);
   }

   clientA.send(msgBundle);
   clientB.send(msgBundle);
   msgBundle.clear();

 }

 //OSC event listener
 void oscEvent(OscBundle msgBundle){
   System.out.println("Received OSC Bundle");
 }

 void shutDown(){
   scClient.stop();
   delay(100);
   server.stop();
   delay(100);
   clientA.stop();
   delay(100);
   clientB.stop();
   delay(100);
   println("Services stopped");
 }
}
Re: OSCP5
Reply #1 - Feb 19th, 2007, 9:27am
 
This is the client-side error:
Address: /sens0
Value: 0.0
Address: null
java.lang.NullPointerException

at Temporary_5723_8357$DataRouter.routeData(Temporary_5723_8357.java:174)

at Temporary_5723_8357.draw(Temporary_5723_8357.java:31)

at processing.core.PApplet.handleDisplay(PApplet.java:1355)

at processing.core.PGraphics.requestDisplay(PGraphics.java:564)

at processing.core.PApplet.run(PApplet.java:1450)

at java.lang.Thread.run(Unknown Source)

java.lang.NullPointerException

at Temporary_5723_8357$DataRouter.routeData(Temporary_5723_8357.java:174)

at Temporary_5723_8357.draw(Temporary_5723_8357.java:31)

at processing.core.PApplet.handleDisplay(PApplet.java:1355)

at processing.core.PGraphics.requestDisplay(PGraphics.java:564)

at processing.core.PApplet.run(PApplet.java:1450)

at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException

at processing.serial.Serial.serialEvent(Serial.java:213)

at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)

at gnu.io.RXTXPort.eventLoop(Native Method)

at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Re: OSCP5
Reply #2 - Feb 19th, 2007, 10:24am
 
Code:

println("Value: "+message.get(1).floatValue()); <<<< BOMBS OUT HERE


just replace the 1 in .get(1) with a 0
to get the first item you would need to go to position 0 in the array from which you are requesting the value.
the error is funny though.

best,
andi
Re: OSCP5
Reply #3 - Feb 19th, 2007, 1:43pm
 
Sorry, I meant to change that back, I tried replacing the 0 with a 1 as a kind of dumb error eliminator, It still gives the same result.
Re: OSCP5
Reply #4 - Feb 19th, 2007, 8:25pm
 
actually the message and the array with the arguments is finally assembled when you send the message. so before that osc arguments are just pushed into a byte array. my only advice can be
Code:

println("Value: "+value); // <<<< NO BOMBING HERE

and trust the lib Smiley

best,
andi
Re: OSCP5
Reply #5 - Feb 25th, 2007, 10:52pm
 
Hi im still having no luck with the TCP OSCP5 so if anyone could help that'd be great =)

Basically, the code above remains, and is designed to act as both client and server on any machine.  The basic idea is to send bundles from one machine to another containing data read in from a wiring board.

I can establish a connection fine, however no bundles are being received on the server machine, and the server process keeps disconnecting with an Array Index Out Of Bounds Exception.  I really have no idea what this refers to since, the only code i have in the oscEvent listener is a Syso to confirm each time a bundle is received......

Any help would be much appreciated...
Re: OSCP5
Reply #6 - Feb 25th, 2007, 11:05pm
 
most of this is a fair distance beyond my comprehension as a Processing/Java programmer, but i may have some information that can help you..

if you are building your project in Processing, nullPointerExceptions are a little janky. i got one when i tried to read a BufferedInputStream into an awt.Image object. the problem was nonexistant after i compiled my code into a native java program rather than one compiled from within the PDE.

if you are already compiling and writing your program from within java, then this post probably does nothing to help you.. and i apologize.

i just know that i had a nullPointerException error occurring where it made no sense to do so.. and migrating the project to native Java (importing processing.core.* and adding my Processing code as an extending class) fixed it.

hope this helps. if not, sorry. Smiley
Re: OSCP5
Reply #7 - Feb 26th, 2007, 2:44pm
 
haliphax wrote on Feb 25th, 2007, 11:05pm:
if you are building your project in Processing, nullPointerExceptions are a little janky. i got one when i tried to read a BufferedInputStream into an awt.Image object. the problem was nonexistant after i compiled my code into a native java program rather than one compiled from within the PDE.

that should absolutely not be the case. if you think it's a bug in processing, then please file a bug in the bugs db.
Re: OSCP5
Reply #8 - Feb 26th, 2007, 7:34pm
 
i will try to track down the code example that was given to me that produced the error.

the error no longer existed when i migrated to eclipse.
Page Index Toggle Pages: 1