File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
Desktop/Application/MaxMix/Services/Communication Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -255,10 +255,12 @@ private void Disconnect()
255255 }
256256 catch { }
257257 }
258+ #endregion
258259
259- private void Receive ( )
260+ #region EventHandlers
261+ private void OnDataReceived ( object sender , SerialDataReceivedEventArgs args )
260262 {
261- while ( _serialPort . BytesToRead > 0 )
263+ while ( ( _serialPort != null ) && ( _serialPort . BytesToRead > 0 ) )
262264 {
263265 byte received = ( byte ) _serialPort . ReadByte ( ) ;
264266 _buffer . Add ( received ) ;
@@ -299,14 +301,6 @@ private void Receive()
299301 }
300302 }
301303 }
302-
303- #endregion
304-
305- #region EventHandlers
306- private void OnDataReceived ( object sender , SerialDataReceivedEventArgs e )
307- {
308- Receive ( ) ;
309- }
310304 #endregion
311305
312306 #region Event Dispatchers
Original file line number Diff line number Diff line change @@ -207,9 +207,14 @@ public IMessage Deserialize(byte[] bytes)
207207 byte [ ] payload = decoded . Skip ( 2 ) . Take ( length - 3 ) . ToArray ( ) ;
208208
209209 // Deserialize payload with message type instance
210- Type type = _registeredTypes [ command ] ;
211210 IMessage message ;
212- if ( type == typeof ( MessageAcknowledgment ) )
211+ Type type = _registeredTypes [ command ] ;
212+ if ( type == null )
213+ {
214+ // Message from an unregistered type, simply ignore it.
215+ return null ;
216+ }
217+ else if ( type == typeof ( MessageAcknowledgment ) )
213218 {
214219 message = Activator . CreateInstance ( type , revision ) as MessageAcknowledgment ;
215220 }
You can’t perform that action at this time.
0 commit comments