Sending OSC message bundles from C# and receiving in Processing got weird address pattern and errors

StackOverflow https://stackoverflow.com/questions/17137358

  •  31-05-2022
  •  | 
  •  

Frage

I am relatively new to programming, so please excuse me if the question is stupid. I am now working on a project which involves Kinect. I am using C# to extract the live joint information (such as position and orientation) and then sending the data into Processing using OSC message -Udp protocal. I sent OSC message bundle from C# the problem is I don't know how to dispatch the message to what I want in Processing. Or possibly, I sent the data in a wrong format in C#. I would be very appreciate if someone can tell me what could possible gone wrong in the code and caused the errors.

I send the joint position from C# by using these code:

    if (joint0.JointType == JointType.ElbowRight)
    {
        // distance in meter
        String temp = "ElbowRight   " + joint0.Position.X * 1000 + "    " + joint0.Position.Y * 1000 + "    " + joint0.Position.Z * 1000;
        Console.WriteLine(temp);
        OscElement message = new OscElement("/joint/" + joint0.JointType.ToString(), joint0.Position.X * 1000, joint0.Position.Y * 1000, joint0.Position.Z, joint0.TrackingState.ToString());
        bundle.AddElement(message);
    }
    OscSender.Send(bundle);   // send message bundle

The part,"/joint/", is the address pattern of the message. The following data are the arguments of the message. According to http://opensoundcontrol.org/spec-1_0 a OSC type tag string should be added following to the address pattern, which is an OSC-string beginning with the character ',' (comma) followed by a sequence of characters corresponding exactly to the sequence of OSC Arguments in the given message. However when I tried this, a format exception was caused and the error was reported as: Invalid character (\44). What I did was simply added ",s" to the OSC message:

OscElement message = new OscElement("/joint/" + ",s" + joint0.JointType.ToString(), joint0.Position.X * 1000, joint0.Position.Y * 1000, joint0.Position.Z, joint0.TrackingState.ToString());

How do I suppose to add the type tag? Can this be the reason that caused the following errors?

In my Processing code, I tried to get the joint position value by using these code:

  if(theOscMessage.checkAddrPattern("/joint")==true) {
      String firstValue = theOscMessage.get(0).stringValue(); 
      float xosc = theOscMessage.get(1).floatValue(); // get the second osc argument
      float yosc = theOscMessage.get(2).floatValue(); // get the second osc argument
      float zosc = theOscMessage.get(3).floatValue(); // get the second osc argument
      String thirdValue = theOscMessage.get(4).stringValue(); // get the third osc argument
      println("### values: "+xosc+", "+xosc+", "+zosc);
      return;
  }

However I got this error: [2013/6/16 20:20:53] ERROR @ UdpServer.run() ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException

Than I tied receiving the messaging using a example given in Processing, which displays the address pattern and type tag of the massage:

println("addrpattern\t"+theOscMessage.addrPattern());
println("typetag\t"+theOscMessage.typetag());

It printed out this:

addrpattern pundle typetag u???N?N?$xlt???

I dont understand what's wrong with the code. Souldn't the address pattern be "joint"? or at least "bundle"? What is the pundle...

P.s. I am using Visual C# 2010 Express and Processing 2.0b9 64bit on a Win7 os computer.

Thank you so much for the help!

Update: Although I still can't figure out how to solve this problem, I found a way to receive messages in Processing. Instead of using OSC bundle, I am sending Osc messages with different address pattern. then use message plug (e.g. oscP5.plug(this,”leftFoot”,”/joint/AnkleLeft”);) in the draw method. Then create a method called leftFoot

public void leftFoot(float fx, float fy, float fz, String state) {
  println("Received: "+fx+", "+fy+", "+fz+", "+state);  
}

Then you can see the data being print out. p.s. in C# the OSC message was send using:

OscElement message = new OscElement("/joint" + "/" + joint0.JointType.ToString(), joint0.Position.X * 1000, joint0.Position.Y * 1000, joint0.Position.Z, joint0.TrackingState.ToString());
                OscSender.Send(message);
War es hilfreich?

Lösung

Hmmm... not sure exactly, but you could just use OSCeleton. It comes with a Processing example - I've used it before, and it works fine.

(the example may also help you understand how to use the OSC address patterns correctly... )

https://github.com/Sensebloom/OSCeleton

https://github.com/Sensebloom/OSCeleton-examples

Andere Tipps

OSC requires padding to next 32-bit boundary, meaning that you need to add zeros to pad the message, until its length is an even multiple of four bytes.

You need to do the same for the typetag. Pad it with zeroes even if you only send one typetag, so ,s00 instead of just ,s

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top