Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

c#: Receiving OSC/TUIO Data works not after build

Discussion in 'Scripting' started by TobiTobsenL, Sep 19, 2015.

  1. TobiTobsenL

    TobiTobsenL

    Joined:
    Sep 19, 2015
    Posts:
    3
    Hi Community,
    I am trying to receive raw TUIO data, underlying structure is as known OSC. It works when I am testing it in the unity development environment but fails when i am trying to run my builded exe file.

    I am scipting with c# and I am using the c# reference implementation which can be found here:
    http://sourceforge.net/projects/rea...1.1.5.zip/download?use_mirror=netix&download=
    From here:
    http://tuio.org/?software

    What I did was to copy the folder TUIO and OSC.NET to my Assets folder. From there I can use them in my scripts.

    Hmm so its working fine when running the project within the unity development environment... After build and starting the exe no reaction when sending TUIO data. Looking into the output_log.txt file that was created by the .exe, I see an excepion that comes up with the first TUIO message sent, saying this:

    An exception was thrown by the type initializer for OSC.NET.OSCPacket
    null packet

    This seems to come up with every TUIO data that was sent.

    The class OSCPacket is abstact:
    abstract public class OSCPacket

    Could this cause the problem?
    Not sure as its running fine when not starting the exe, so i was thinking it might be some missing ressources or sth?

    Maybe someone else has a smart idea?

    Thanks & Cheers,
    Tobi
     
  2. TobiTobsenL

    TobiTobsenL

    Joined:
    Sep 19, 2015
    Posts:
    3
    Hi There,
    so I did change to another, more simple, Tuio C# implementation:
    https://github.com/valyard/TUIOsharp

    It needed a bit more programming on my side but now its working fine also after building the exe file.

    Still I don't know why it did not work with the other implementation.

    Cheers,
    Tobi
     
  3. Surg

    Surg

    Joined:
    Jun 29, 2013
    Posts:
    5
    @TobiTobsenL Do you have any explanation/tutorial how to use your library.
    Very interested in testing out TUIO using unity!
     
    kenshin likes this.
  4. TobiTobsenL

    TobiTobsenL

    Joined:
    Sep 19, 2015
    Posts:
    3
    Hi Surg,
    so like I wrote, the standard TUIO C# implentation did crash after buidling the exe file and trying to run this.

    So I was using this more simple implementation:
    https://github.com/valyard/TUIOsharp

    I added the folders OSCsharp and TUIOsharp to my Assets.
    TUIO uses the OSC implementation, so you need both although you will only talk to TUIOsharp.
    I wrote a class called TuioHandling() that does the TUIO handling and attached this one to the MainCamera.


    In this skrip you have to create a TuioServer:
    TuioServer tuioserver;

    Now this is not the nicest programming design but was ok for my purpose: The TuioServer needs to know who to call when there are new TUIO data - this is why I added a TuioHandling() object to the TuioServer() class. This TuioHandling() object is called when there are new data available, this happens in TuioServer():

    private void handlerOscMessageReceived(object sender, OscMessageReceivedEventArgs oscMessageReceivedEventArgs)
    {
    parseOscMessage(oscMessageReceivedEventArgs.Message);
    this.tuioMain.callMeOnNewCursors(this.updatedCursors, this.addedCursors, this.removedCursors);
    }

    the method callMeOnNewCursors() is in my TuioHandling class and this is where I process the Tuio data.


    Now you have to create the TuioServer, I did init this in the Start() method in TuioHandling:
    tuioServer = new TuioServer(this);
    tuioServer.Connect();

    You can see with (this) the TuioServer() gets the link to the TuioHandling().

    OnApplicationQuit() you should disconnect:
    tuioServer.Disconnect();


    If I find time I will prepare a clean version of my implementation and upload it, this will make things easier.
    But in the end you will only receive raw TUIO data, thats pretty low level data that need to be processed somehow.

    Best regards
    Tobi
     
  5. glvenlan

    glvenlan

    Joined:
    Mar 31, 2013
    Posts:
    1
    For my case, the Encoding.GetEncoding(1252) function at static OSCPacket() in class OSC.NET.OSCPacket caused the problem above.
    Log all exception would show that the builded exe file could not find the specified code page 1252.
    Just change to ASCIIEncoding8Bit = Encoding.Default would fixed the problem.
     
    svnsms, Deleted User and oculartech like this.
  6. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    22
    Saved my day, thank you!
     
  7. oculartech

    oculartech

    Joined:
    Jan 9, 2020
    Posts:
    2