@@ -48,6 +48,10 @@ public class SerialController : MonoBehaviour
48
48
"newest messages from the port." ) ]
49
49
public bool dropOldMessage ;
50
50
51
+ [ Tooltip ( "Read all unread messages in the queue during every Update loop. " +
52
+ "Only used when \" Message Listener\" is provided." ) ]
53
+ public bool readAllMessages ;
54
+
51
55
// Constants used to mark the start and end of a connection. There is no
52
56
// way you can generate clashing messages from your serial device, as I
53
57
// compare the references of these strings, no their contents. So if you
@@ -106,10 +110,8 @@ void OnDisable()
106
110
}
107
111
108
112
// ------------------------------------------------------------------------
109
- // Polls messages from the queue that the SerialThread object keeps. Once a
110
- // message has been polled it is removed from the queue. There are some
111
- // special messages that mark the start/end of the communication with the
112
- // device.
113
+ // Calls message polling every frame. Does nothing when message listener
114
+ // is not provided.
113
115
// ------------------------------------------------------------------------
114
116
void Update ( )
115
117
{
@@ -118,6 +120,23 @@ void Update()
118
120
if ( messageListener == null )
119
121
return ;
120
122
123
+ // If the user prefers to read all messages, then enter a loop
124
+ // and read messages until the queue is empty
125
+ if ( readAllMessages )
126
+ while ( serialThread . InputQueueCount ( ) > 0 )
127
+ ReadSerialMessageToMessageListener ( ) ;
128
+ else
129
+ ReadSerialMessageToMessageListener ( ) ;
130
+ }
131
+
132
+ // ------------------------------------------------------------------------
133
+ // Polls messages from the queue that the SerialThread object keeps. Once a
134
+ // message has been polled it is removed from the queue. There are some
135
+ // special messages that mark the start/end of the communication with the
136
+ // device.
137
+ // ------------------------------------------------------------------------
138
+ private void ReadSerialMessageToMessageListener ( )
139
+ {
121
140
// Read the next message from the queue
122
141
string message = ( string ) serialThread . ReadMessage ( ) ;
123
142
if ( message == null )
0 commit comments