How to connect processing with gh using UDP or OSC?

edited May 31 in Library Questions

Hi there, I am trying to receive some data from grasshopper, and I firstly use OCSP5 library, which allows sending message to gh but cannot receive. And I tried UDP class, but the processing keeps saying the library cannot be used... I was wondering is there a way to get the newer version of the UDP library, or is there a way to receiving data from grasshopper?

Thanks!

I am really try with a simple sketch.

import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;

float mySum;

void setup()
{
  frameRate(25);
  oscP5 = new OscP5(this,12000);
  myRemoteLocation = new NetAddress("10.10.15.157",12000);
  oscP5.addListener(myListener);
  mySum = 0;
}

void draw()
{
  background(0);
}

/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  print ("oscEvent"+theOscMessage.addrPattern()+theOscMessage.arguments());
}

and when I send data from grasshopper, the console says NullPointerException, and print something in console like

java.lang.NullPointerException
    at oscP5.OscP5.callMethod(Unknown Source)
    at oscP5.OscP5.process(Unknown Source)
    at oscP5.OscNetManager.process(Unknown Source)
    at netP5.AbstractUdpServer.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:748)

I commented the initiation for Add listener, and it worked...sorry I've got this in console

oscEvent/GH/none[Ljava.lang.Object;@54f912f5

Thanks for your time!

==============================

update Now my new sketch, what troubles me now is that I don't want the java object, but a list of doubles. But I got Error in console

code:

import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
OscMessage arrayMsg = new OscMessage("/array");

void setup()
{
  frameRate(25);
  oscP5 = new OscP5(this,12000);
  myRemoteLocation = new NetAddress("10.10.15.157",12000);
}

void draw()
{
  background(0);
}

void oscEvent(OscMessage theOscMessage) {
  println("Address pattern: "+theOscMessage.addrPattern());
  println ("Typetag: "+theOscMessage.typetag());
  println ("Arguments: "+theOscMessage.get(0).doubleValue());
}

and the console prints

Address pattern: /test01
Typetag: ssss
### [2018/5/31 15:22:4] ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage
 to a method in your program. please check your code for any 
possible errors that might occur in the method where incoming
 OscMessages are parsed e.g. check for casting errors, possible
 nullpointers, array overflows ... .
method in charge : oscEvent  java.lang.reflect.InvocationTargetException

Answers

  • Where do you instantiate the listener?

  • @koogs I do not know how to initiate it... Anyway I commented it and the sketch works without the listener

  • And I tried UDP class, but the processing keeps saying the library cannot be used

    Where does this msg show up?

    I don't think you need the listener for the example above. So I guess this is the code you are using to test your receiving case? What lines gets highlight when you get the NPE?

    Can you run wireshark and capture some of the packages being sent by GH? (No experience with GH as I think that is sw that runs on macs. Anyways, checking the data is being sent is the first thing I would test.

    Kf

  • @kfrajer The message shows up as a red background banner above the console. And the line is

    udps = new UDP( this, 6005 ); //sending from this port

    which is the third line in the setup{}

    Sorry I deleted the UDP section in the question cos I figured out how to receive my message via oscP5, don't want to make confusion.

    Also may I ask how to translate the java object I received into a string or string array..? cos I received

    oscEvent/GH/none[Ljava.lang.Object;@54f912f5

    this kind of thing in my console...

  • looking at this: http://www.sojamo.com/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde

    that adds an int, a float and a string to the message. the message typetag ends up as "ifs", which suggests "s" is for string. you're getting "Typetag: ssss", four strings, but you appear to be trying to read that as a double.

  • @koogs !! finally I can receive the proper message. Many thanks!!!

Sign In or Register to comment.