// ------------------------------------------------------------------------ // Polls messages from the queue that the SerialThread object keeps. Once a // message has been polled it is removed from the queue. There are some // special messages that mark the start/end of the communication with the // device. // ------------------------------------------------------------------------ void Update() { // If the user prefers to poll the messages instead of receiving them // via SendMessage, then the message listener should be null. if (Messager == null) { return; } // Read the next message from the queue int messages = 0; string message = (string)serialThread.ReadMessage(); while (message != null) { // Check if the message is plain data or a connect/disconnect event. if (ReferenceEquals(message, SERIAL_DEVICE_CONNECTED)) { Messager.ConnectionEventFromArduino(true); } else if (ReferenceEquals(message, SERIAL_DEVICE_DISCONNECTED)) { Messager.ConnectionEventFromArduino(false); } else { Messager.MessageFromArduino(message); } message = (string)serialThread.ReadMessage(); messages++; } // if(messages>0)Debug.Log($"Serial Controller processed {messages} message(s)"); }