Forum

You must be logged in to post Login


Lost Your Password?

Search Forums:


 






Wildcard Usage:
*    matches any number of characters
%    matches exactly one character

How do I send more than one message using OscMessage?

No Tags
UserPost

11:15 am
November 18, 2010


Spa8nky

Guest

I can send a message with

OscMessage message = new OscMessage(endPoint, cmdName, value);

How  can I have more than just one value for the value?  In other words the OSC Message received will not just be one value but an array of values?

I can't use an array it seems as this is an unsupported data type.

Thanks

11:28 am
November 18, 2010


Paul

Admin

posts 49

There are multiple OscMessage constructors — the one you mentioned is a convenience constructor that allows a value to be appended to the message during instantiation. You can always add new data to the message through the OscMessage.Append() method.

Also, arrays are certainly supported — but they must be converted to byte arrays. This library natively supports 32-bit ints, 64-bit ints, floats, doubles, strings, and byte arrays. Ultimately, everything can be converted to a byte array — so in this fashion the library can serialize any type of data.

Paul

4:32 pm
November 18, 2010


Spa8nky

Guest

I see.  So is the append method the only way to do this?

 

I've come up with the following:

 

        public void Send(string cmdName, params object[] values)
        {
            OscMessage message = new OscMessage(endPoint, cmdName, values[0]);
            for (int i = 1; i < values.Length; ++i)
            {
                message.Append<object>(values[i]);
            }
            message.Send(endPoint);
        }
  Thanks for the help Paul.

1:08 pm
November 19, 2010


Paul

Admin

posts 49

Your code looks fine, though I find it a bit odd to use the constructor version for appending values[0] and then the for-loop for values 1 through n. There's nothing wrong with what you've written, just seems a little strange. More readable would be to use the ctor version:

OscMessage message = new OscMessage(endPoint, cmdName);

and then iterate from 0 to values.Length for appending all of the elements of your array.

Also, keep in mind that not all data types are directly supported. So your object[] must only contain the data types I'd mentioned in my previous post. Otherwise, you'll need to add some code in your example to convert any unsupported types into byte arrays.

Paul

4:05 pm
November 19, 2010


Spa8nky

Guest

Thanks Paul.  Changed the method as instructed.  It does make more sense that way :)

No Tags

About the Bespoke Software forum



No Comment

Comments are closed.