Serial.ReadSerialLoop C# (CSharp) Method

ReadSerialLoop() public method

public ReadSerialLoop ( ) : IEnumerator
return IEnumerator
    public IEnumerator ReadSerialLoop()
    {
        while (true) {

            if (!enabled) {
                //print ("behaviour not enabled, stopping coroutine");
                yield break;
            }

            //print("ReadSerialLoop ");
            nCoroutineRunning++;

            try {
                s_lastDataCheck = Time.time;
                while (s_serial.BytesToRead > 0) {  // BytesToRead crashes on Windows -> use ReadLine or ReadByte in a Thread or Coroutine

                    string serialIn = s_serial.ReadExisting ();

                    // Dispatch new data to each instance
                    foreach (Serial inst in s_instances) {
                        inst.receivedData (serialIn);
                    }

                    s_lastDataIn = s_lastDataCheck;
                }

            } catch (System.Exception e) {
                print ("System.Exception in serial.ReadExisting: " + e.ToString ());
            }

            yield return null;
        }
    }