Skip to content

Commit 26aced4

Browse files
authored
Add ReadBufferSize and WriteBufferSize (#62)
1 parent e62142c commit 26aced4

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

System.IO.Ports/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
////////////////////////////////////////////////////////////////
1414
// update this whenever the native assembly signature changes //
15-
[assembly: AssemblyNativeVersion("100.1.3.0")]
15+
[assembly: AssemblyNativeVersion("100.1.4.0")]
1616
////////////////////////////////////////////////////////////////
1717

1818
// Setting ComVisible to false makes the types in this assembly not visible

System.IO.Ports/SerialPort.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public sealed class SerialPort : IDisposable
4949
private SerialDataReceivedEventHandler _callbacksDataReceivedEvent = null;
5050
private SerialStream _stream;
5151
private string _newLine;
52+
private int _bufferSize = 256;
5253

5354
/// <summary>
5455
/// Initializes a new instance of the <see cref="SerialPort"/> class using the
@@ -101,6 +102,7 @@ public SerialPort(
101102
/// <exception cref="InvalidOperationException">The specified port on the current instance of the <see cref="SerialPort"/>.
102103
/// is already open.</exception>
103104
/// <exception cref="ArgumentException">One (or more) of the properties set to configure this <see cref="SerialPort"/> are invalid.</exception>
105+
/// <exception cref="OutOfMemoryException">Failed to allocate the request amount of memory for the work buffer.</exception>
104106
public void Open()
105107
{
106108
if (!_opened)
@@ -484,6 +486,86 @@ public extern bool InvertSignalLevels
484486
set;
485487
}
486488

489+
/// <summary>
490+
/// Gets or sets the size of the SerialPort input buffer.
491+
/// </summary>
492+
/// <value>The size of the input buffer. The default is 256.</value>
493+
/// <exception cref="ArgumentOutOfRangeException">The <see cref="ReadBufferSize"/> value is less than or equal to zero.</exception>
494+
/// <exception cref="InvalidOperationException">The <see cref="ReadBufferSize"/> property was set while the stream was open.</exception>
495+
/// <remarks>
496+
/// <para>
497+
/// Implementation of this property for .NET nanoFramework it's slightly different from .NET.
498+
/// </para>
499+
/// <para>
500+
/// - There is only one work buffer which is used for transmission and reception.
501+
/// </para>
502+
/// <para>
503+
/// - When the <see cref="SerialPort"/> is <see cref="Open"/> the driver will try to allocate the requested memory for the buffer. On failure to do so, an <see cref="OutOfMemoryException"/> exception will be throw and the <see cref="Open"/> operation will fail.
504+
/// </para>
505+
/// </remarks>
506+
public int ReadBufferSize
507+
{
508+
set
509+
{
510+
if (value <= 0)
511+
{
512+
throw new ArgumentOutOfRangeException();
513+
}
514+
515+
if (_opened)
516+
{
517+
throw new InvalidOperationException();
518+
}
519+
520+
_bufferSize = value;
521+
}
522+
523+
get
524+
{
525+
return _bufferSize;
526+
}
527+
}
528+
529+
/// <summary>
530+
/// Gets or sets the size of the serial port output buffer.
531+
/// </summary>
532+
/// <value>The size of the output buffer. The default is 256.</value>
533+
/// <exception cref="ArgumentOutOfRangeException">The <see cref="WriteBufferSize"/> value is less than or equal to zero.</exception>
534+
/// <exception cref="InvalidOperationException">The <see cref="WriteBufferSize"/> property was set while the stream was open.</exception>
535+
/// <remarks>
536+
/// <para>
537+
/// Implementation of this property for .NET nanoFramework it's slightly different from .NET.
538+
/// </para>
539+
/// <para>
540+
/// - There is only one work buffer which is used for transmission and reception.
541+
/// </para>
542+
/// <para>
543+
/// - When the <see cref="SerialPort"/> is <see cref="Open"/> the driver will try to allocate the requested memory for the buffer. On failure to do so, an <see cref="OutOfMemoryException"/> exception will be throw and the <see cref="Open"/> operation will fail.
544+
/// </para>
545+
/// </remarks>
546+
public int WriteBufferSize
547+
{
548+
set
549+
{
550+
if (value <= 0)
551+
{
552+
throw new ArgumentOutOfRangeException();
553+
}
554+
555+
if (_opened)
556+
{
557+
throw new InvalidOperationException();
558+
}
559+
560+
_bufferSize = value;
561+
}
562+
563+
get
564+
{
565+
return _bufferSize;
566+
}
567+
}
568+
487569
#endregion
488570

489571
/// <summary>

0 commit comments

Comments
 (0)