Пример #1
0
    // ------------------------------------------------------------------------
    // Invoked whenever the CammaController gameobject is deactivated.
    // It stops and destroys the thread that was reading from the camma device.
    // ------------------------------------------------------------------------
    void OnDisable()
    {
        // If there is a user-defined tear-down function, execute it before
        // closing the underlying COM port.
        if (userDefinedTearDownFunction != null)
        {
            userDefinedTearDownFunction();
        }

        // The cammaThread reference should never be null at this point,
        // unless an Exception happened in the OnEnable(), in which case I've
        // no idea what face Unity will make.
        if (cammaThread != null)
        {
            cammaThread.RequestStop();
            cammaThread = null;
        }

        // This reference shouldn't be null at this point anyway.
        if (thread != null)
        {
            thread.Join();
            thread = null;
        }
    }
Пример #2
0
    void OnEnable()
    {
        string portName = CammaFindServer();
        int    baudRate = 1843200;

        cammaThread = new CammaThreadLines(portName,
                                           baudRate,
                                           reconnectionDelay,
                                           maxUnreadMessages);
        thread = new Thread(new ThreadStart(cammaThread.RunForever));
        thread.Start();
    }