Skip to content

Commit 490f994

Browse files
authored
Merge pull request #151 from quadbyte/com_hotfix
Com Fix for Sentry' s issues
2 parents e2ea716 + fc1bf2b commit 490f994

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

Desktop/Application/MaxMix/Services/Communication/CommunicationService.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff 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

Desktop/Application/MaxMix/Services/Communication/Serial/CobsSerializationService .cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)