|
1 | | - |
| 1 | +// |
| 2 | +// Copyright (c) .NET Foundation and Contributors |
| 3 | +// See LICENSE file in the project root for full license information. |
| 4 | +// |
| 5 | + |
2 | 6 | using System.Runtime.CompilerServices; |
3 | 7 | using System.Text; |
4 | 8 | using System.Collections; |
@@ -38,7 +42,7 @@ public class SerialPort : IDisposable |
38 | 42 | private char _watchChar; |
39 | 43 | private SerialDataReceivedEventHandler _callbacksDataReceivedEvent = null; |
40 | 44 | private SerialStream _stream; |
41 | | - private object _syncLock; |
| 45 | + private readonly object _syncLock; |
42 | 46 | private string _newLine; |
43 | 47 | private bool _hasBeenOpened = false; |
44 | 48 |
|
@@ -270,7 +274,7 @@ public StopBits StopBits |
270 | 274 | /// Gets or sets the port for communications, including but not limited to all available |
271 | 275 | /// COM ports. |
272 | 276 | /// </summary> |
273 | | - /// <exception cref=ArgumentException"">The System.IO.Ports.SerialPort.PortName property was set to a value with a length |
| 277 | + /// <exception cref="ArgumentException">The System.IO.Ports.SerialPort.PortName property was set to a value with a length |
274 | 278 | /// of zero. -or- The System.IO.Ports.SerialPort.PortName property was set to a value |
275 | 279 | /// that starts with "\\". -or- The port name was not valid.</exception> |
276 | 280 | /// <exception cref="ArgumentNullException">The System.IO.Ports.SerialPort.PortName property was set to null.</exception> |
@@ -611,8 +615,8 @@ public string ReadExisting() |
611 | 615 | } |
612 | 616 |
|
613 | 617 | byte[] toRead = new byte[BytesToRead]; |
614 | | - var ret = NativeRead(toRead, 0, toRead.Length); |
615 | | - // normally ret == toRead.Length |
| 618 | + NativeRead(toRead, 0, toRead.Length); |
| 619 | + // An exception is thrown if timeout, so we are sure to read only 1 byte properly |
616 | 620 | return Encoding.GetString(toRead, 0, toRead.Length); |
617 | 621 | } |
618 | 622 |
|
@@ -837,6 +841,9 @@ protected void Dispose(bool disposing) |
837 | 841 | } |
838 | 842 | } |
839 | 843 |
|
| 844 | + /// <summary> |
| 845 | + /// Dispose the Serial Port |
| 846 | + /// </summary> |
840 | 847 | public void Dispose() |
841 | 848 | { |
842 | 849 | lock (_syncLock) |
|
0 commit comments