Skip to content

Commit

Permalink
Add NewLine property
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 21, 2022
1 parent 500edd8 commit fa17d3c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<Authors>Chris Pulman</Authors>
<TargetFrameworks>net461;netstandard2.0;net6.0;</TargetFrameworks>
<Description>An Observable Com port extension of System.IO.Ports.SerialPort</Description>
Expand Down Expand Up @@ -32,4 +32,4 @@
<PackageReference Include="Roslynator.Analyzers" Version="4.1.1" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
</Project>
8 changes: 8 additions & 0 deletions SerialPortRx/ISerialPortRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public interface ISerialPortRx : IDisposable
/// <value>The write timeout.</value>
int WriteTimeout { get; set; }

/// <summary>
/// Gets or sets the new line.
/// </summary>
/// <value>
/// The new line.
/// </value>
string NewLine { get; set; }

/// <summary>
/// Closes this instance.
/// </summary>
Expand Down
40 changes: 20 additions & 20 deletions SerialPortRx/SerialPortRx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ public SerialPortRx()
[MonitoringDescription("WriteTimeout")]
public int WriteTimeout { get; set; } = -1;

/// <summary>
/// Gets or sets creates new line.
/// </summary>
/// <value>
/// The new line.
/// </value>
[Browsable(false)]
[DefaultValue("\n")]
[MonitoringDescription("NewLine")]
public string NewLine { get; set; } = "\n";

private IObservable<Unit> Connect => Observable.Create<Unit>(obs =>
{
var dis = new CompositeDisposable();
Expand All @@ -252,8 +263,10 @@ public SerialPortRx()
{
// Setup Com Port
var port = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBits);

dis.Add(port);
port.Close();
port.NewLine = NewLine;
port.Handshake = Handshake;
port.ReadTimeout = ReadTimeout;
port.WriteTimeout = WriteTimeout;
Expand Down Expand Up @@ -399,10 +412,7 @@ public static IObservable<string[]> PortNames(int pollInterval = 500, int pollLi
/// <summary>
/// Closes this instance.
/// </summary>
public void Close()
{
_disposablePort?.Dispose();
}
public void Close() => _disposablePort?.Dispose();

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting
Expand All @@ -420,30 +430,24 @@ public void Dispose()
/// <returns>
/// A Task.
/// </returns>
public Task Open()
{
return _disposablePort?.Count == 0 ? Task.Run(() => Connect.Subscribe().AddTo(_disposablePort)) : Task.CompletedTask;
}
public Task Open() =>
_disposablePort?.Count == 0 ? Task.Run(() => Connect.Subscribe().AddTo(_disposablePort)) : Task.CompletedTask;

/// <summary>
/// Writes the specified text.
/// </summary>
/// <param name="text">The text.</param>
public void Write(string text)
{
public void Write(string text) =>
_writeString?.OnNext(text);
}

/// <summary>
/// Writes the specified byte array.
/// </summary>
/// <param name="byteArray">The byte array.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
public void Write(byte[] byteArray, int offset, int count)
{
public void Write(byte[] byteArray, int offset, int count) =>
_writeByte?.OnNext(new Tuple<byte[], int, int>(byteArray, offset, count));
}

/// <summary>
/// Writes the specified byte array.
Expand Down Expand Up @@ -479,19 +483,15 @@ public void Write(char[] charArray)
/// <param name="charArray">The character array.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
public void Write(char[] charArray, int offset, int count)
{
public void Write(char[] charArray, int offset, int count) =>
_writeChar?.OnNext(new Tuple<char[], int, int>(charArray, offset, count));
}

/// <summary>
/// Writes the line.
/// </summary>
/// <param name="text">The text.</param>
public void WriteLine(string text)
{
public void WriteLine(string text) =>
_writeStringLine?.OnNext(text);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
Expand Down
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.1.2",
"version": "2.1.3",
"nuGetPackageVersion": {
"semVer": 2.0
},
Expand Down

0 comments on commit fa17d3c

Please sign in to comment.