示例#1
0
 /// <summary>
 /// Begin reading robot print-outs into the string buffer
 /// </summary>
 private static void OpenPrintStream()
 {
     printStreamOpen = true;
     if (remoteReader == null)
     {
         remoteReader = EmulatorManager.CreateRobotOutputStream();
     }
     while (remoteReader != null && EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting() && EmulatorManager.IsRobotOutputStreamGood() && Instance && RobotIOPanel.Instance.enablePrints)
     {
         try
         {
             int r = remoteReader.Read();
             if (r != -1)
             {
                 char c = (char)r;
                 if (c == '\n' && (newPrintBuffer.Length > MIN_LINE_BUFFER_LEN || timeoutTimer.ElapsedMilliseconds > TIMEOUT)) // Concatenate multiple short prints if in quick enough succession
                 {
                     timeoutTimer.Restart();
                     newPrintQueue.Enqueue(newPrintBuffer);
                     newPrintBuffer = "";
                 }
                 else
                 {
                     newPrintBuffer += c;
                 }
             }
         }
         catch (Exception e)
         {
             Debug.Log(e.ToString());
             break;
         }
     }
     if (remoteReader != null)
     {
         remoteReader.Dispose();
         remoteReader = null;
         if (EmulatorManager.IsRobotOutputStreamGood())
         {
             EmulatorManager.CloseRobotOutputStream();
         }
     }
     printStreamOpen = false;
 }