Exemple #1
0
 /// <summary>
 /// Retreive the Data from the Serial Prot using Unity Coroutines
 /// </summary>
 /// <param name="target"></param>
 /// <returns>null</returns>
 public IEnumerator ReadSerial(string target = null)
 {
     while (true)
     {
         UduinoDevice uduino = null;
         if (target != null && uduinoDevices.TryGetValue(target, out uduino))
         {
             uduino.WriteToArduinoLoop();
             if (uduino.read != null)
             {
                 uduino.ReadFromArduino(uduino.read);
                 uduino.ReadFromArduinoLoop();
                 yield return(null);
             }
             else
             {
                 yield return(null);
             }
         }
         else
         {
             foreach (KeyValuePair <string, UduinoDevice> uduinoDevice in uduinoDevices)
             {
                 uduinoDevice.Value.ReadFromArduinoLoop();
                 uduinoDevice.Value.WriteToArduinoLoop();
             }
             yield return(null);
         }
     }
 }
Exemple #2
0
        /// <summary>
        ///  Read the Serial Port data in a new thread.
        /// </summary>
        public void ReadPorts()
        {
            while (IsRunning())
            {
                // Debug.Log(autoRead);
                lock (uduinoDevices)
                {
                    string[] keys = new string[uduinoDevices.Count];
                    for (int i = 0; i < uduinoDevices.Count; i++)
                    {
                        uduinoDevices.Keys.CopyTo(keys, i);
                    }

                    foreach (string key in keys)
                    {
                        UduinoDevice device = uduinoDevices[key];
                        device.WriteToArduinoLoop();
                        device.ReadFromArduinoLoop();
                    }
                }
                if (limitSendRate)
                {
                    Thread.Sleep((int)sendRateSpeed / 2);
                }
            }
        }