Esempio n. 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;
 }
Esempio n. 2
0
        public void ToggleRobotPrints()
        {
            bool newEnable = !enablePrints;

            // TODO warn and wait if last command didnt finish
            if (!enablePrints && newEnable && EmulatorManager.IsRobotOutputStreamGood()) // When trying to enable, wait until old connection closes
            {
                UserMessageManager.Dispatch("Waiting to close last readout connection", EmulationWarnings.WARNING_DURATION);
            }
            else
            {
                enablePrints = newEnable;
                enablePrintsButtonImage.sprite = enablePrints ? SelectedButtonImage : UnselectedButtonImage;
                if (enablePrints && !EmulatorManager.IsTryingToRunRobotCode())
                {
                    UserMessageManager.Dispatch("Readout enabled, waiting for robot program to start", EmulationWarnings.WARNING_DURATION);
                }
            }
        }