Smdn.Devices.BP35XX version 2.0.0
smdn
released this
06 Sep 12:02
·
33 commits
to main
since this release
Released package
Release notes
The full release notes are available at gist.
Change log
Change log in this release:
- 2024-09-06 update assembly version
- 2024-09-06 fix type accesssibility
- 2024-09-06 add support for using flow control with BP35A1
- 2024-09-06 make IBP35SerialPortStreamFactory disposable
- 2024-09-06 add CompatibilitySuppressions.xml for removing IBP35Configurations
- 2024-09-05 rename file to follow the type name changing
- 2024-09-05 remove IBP35Configurations
- 2024-07-04 send SKRESET on initialization
- 2024-04-07 enable configuring package validation
API changes
API changes in this release:
diff --git a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net6.0.apilist.cs b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net6.0.apilist.cs
index b86796d..804d164 100644
--- a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net6.0.apilist.cs
+++ b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net6.0.apilist.cs
@@ -1,110 +1,103 @@
-// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-1.0.0)
+// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-2.0.0)
// Name: Smdn.Devices.BP35XX
-// AssemblyVersion: 1.0.0.0
-// InformationalVersion: 1.0.0+e4163ada5b034b45c5cc0dac179b412cf54198cd
+// AssemblyVersion: 2.0.0.0
+// InformationalVersion: 2.0.0+ef185af5c73268aab02d6909202fffce4560122b
// TargetFramework: .NETCoreApp,Version=v6.0
// Configuration: Release
// Referenced assemblies:
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Smdn.Fundamental.PrintableEncoding.Hexadecimal, Version=3.0.0.0, Culture=neutral
// Smdn.Net.SkStackIP, Version=1.0.0.0, Culture=neutral
// System.ComponentModel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.IO.Ports, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Memory, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Net.NetworkInformation, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Net.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations
using System;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using Smdn.Devices.BP35XX;
using Smdn.Net.SkStackIP;
namespace Smdn.Devices.BP35XX {
- public interface IBP35Configurations {
- BP35UartBaudRate BaudRate { get; }
- SkStackERXUDPDataFormat ERXUDPDataFormat { get; }
- string? SerialPortName { get; }
- bool TryLoadFlashMemory { get; }
- }
-
- public interface IBP35SerialPortStreamFactory {
- Stream CreateSerialPortStream(IBP35Configurations configurations);
+ public interface IBP35SerialPortStreamFactory : IDisposable {
+ Stream CreateSerialPortStream(string? serialPortName);
}
public enum BP35UartBaudRate : byte {
Baud115200 = 0,
Baud19200 = 4,
Baud2400 = 1,
Baud38400 = 5,
Baud4800 = 2,
Baud57600 = 6,
Baud9600 = 3,
}
public enum BP35UartCharacterInterval : byte {
Microseconds100 = 16,
Microseconds200 = 32,
Microseconds300 = 48,
Microseconds400 = 64,
Microseconds50 = 80,
None = 0,
}
public enum BP35UartFlowControl : byte {
Disabled = 0,
Enabled = 128,
}
public enum BP35UdpReceiveDataFormat : byte {
Binary = 0,
HexAscii = 1,
}
public class BP35A1 : BP35Base {
public static ValueTask<BP35A1> CreateAsync(BP35A1Configurations configurations, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
public static ValueTask<BP35A1> CreateAsync(string? serialPortName, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
}
- public sealed class BP35A1Configurations : IBP35Configurations {
+ public sealed class BP35A1Configurations {
public BP35A1Configurations() {}
public BP35UartBaudRate BaudRate { get; set; }
public string? SerialPortName { get; set; }
- SkStackERXUDPDataFormat IBP35Configurations.ERXUDPDataFormat { get; }
public bool TryLoadFlashMemory { get; set; }
+ public bool UseFlowControl { get; set; }
}
public abstract class BP35Base : SkStackClient {
public IPAddress LinkLocalAddress { get; }
public PhysicalAddress MacAddress { get; }
public string RohmPassword { get; }
public string RohmUserId { get; }
public string SkStackAppVersion { get; }
public Version SkStackVersion { get; }
public async ValueTask<BP35UartConfigurations> GetUartOptionsAsync(CancellationToken cancellationToken = default) {}
public async ValueTask<BP35UdpReceiveDataFormat> GetUdpDataFormatAsync(CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval = BP35UartCharacterInterval.None, BP35UartFlowControl flowControl = BP35UartFlowControl.Disabled, CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartConfigurations uartConfigurations, CancellationToken cancellationToken = default) {}
public ValueTask SetUdpDataFormatAsync(BP35UdpReceiveDataFormat format, CancellationToken cancellationToken = default) {}
}
public readonly struct BP35UartConfigurations {
public BP35UartConfigurations(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval, BP35UartFlowControl flowControl) {}
public BP35UartBaudRate BaudRate { get; }
public BP35UartCharacterInterval CharacterInterval { get; }
public BP35UartFlowControl FlowControl { get; }
public void Deconstruct(out BP35UartBaudRate baudRate, out BP35UartCharacterInterval characterInterval, out BP35UartFlowControl flowControl) {}
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.4.1.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.3.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
diff --git a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net8.0.apilist.cs b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net8.0.apilist.cs
index d0204eb..f383021 100644
--- a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net8.0.apilist.cs
+++ b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-net8.0.apilist.cs
@@ -1,110 +1,103 @@
-// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-1.0.0)
+// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-2.0.0)
// Name: Smdn.Devices.BP35XX
-// AssemblyVersion: 1.0.0.0
-// InformationalVersion: 1.0.0+e4163ada5b034b45c5cc0dac179b412cf54198cd
+// AssemblyVersion: 2.0.0.0
+// InformationalVersion: 2.0.0+ef185af5c73268aab02d6909202fffce4560122b
// TargetFramework: .NETCoreApp,Version=v8.0
// Configuration: Release
// Referenced assemblies:
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Smdn.Fundamental.PrintableEncoding.Hexadecimal, Version=3.0.0.0, Culture=neutral
// Smdn.Net.SkStackIP, Version=1.0.0.0, Culture=neutral
// System.ComponentModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.IO.Ports, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Memory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Net.NetworkInformation, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Net.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations
using System;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using Smdn.Devices.BP35XX;
using Smdn.Net.SkStackIP;
namespace Smdn.Devices.BP35XX {
- public interface IBP35Configurations {
- BP35UartBaudRate BaudRate { get; }
- SkStackERXUDPDataFormat ERXUDPDataFormat { get; }
- string? SerialPortName { get; }
- bool TryLoadFlashMemory { get; }
- }
-
- public interface IBP35SerialPortStreamFactory {
- Stream CreateSerialPortStream(IBP35Configurations configurations);
+ public interface IBP35SerialPortStreamFactory : IDisposable {
+ Stream CreateSerialPortStream(string? serialPortName);
}
public enum BP35UartBaudRate : byte {
Baud115200 = 0,
Baud19200 = 4,
Baud2400 = 1,
Baud38400 = 5,
Baud4800 = 2,
Baud57600 = 6,
Baud9600 = 3,
}
public enum BP35UartCharacterInterval : byte {
Microseconds100 = 16,
Microseconds200 = 32,
Microseconds300 = 48,
Microseconds400 = 64,
Microseconds50 = 80,
None = 0,
}
public enum BP35UartFlowControl : byte {
Disabled = 0,
Enabled = 128,
}
public enum BP35UdpReceiveDataFormat : byte {
Binary = 0,
HexAscii = 1,
}
public class BP35A1 : BP35Base {
public static ValueTask<BP35A1> CreateAsync(BP35A1Configurations configurations, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
public static ValueTask<BP35A1> CreateAsync(string? serialPortName, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
}
- public sealed class BP35A1Configurations : IBP35Configurations {
+ public sealed class BP35A1Configurations {
public BP35A1Configurations() {}
public BP35UartBaudRate BaudRate { get; set; }
public string? SerialPortName { get; set; }
- SkStackERXUDPDataFormat IBP35Configurations.ERXUDPDataFormat { get; }
public bool TryLoadFlashMemory { get; set; }
+ public bool UseFlowControl { get; set; }
}
public abstract class BP35Base : SkStackClient {
public IPAddress LinkLocalAddress { get; }
public PhysicalAddress MacAddress { get; }
public string RohmPassword { get; }
public string RohmUserId { get; }
public string SkStackAppVersion { get; }
public Version SkStackVersion { get; }
public async ValueTask<BP35UartConfigurations> GetUartOptionsAsync(CancellationToken cancellationToken = default) {}
public async ValueTask<BP35UdpReceiveDataFormat> GetUdpDataFormatAsync(CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval = BP35UartCharacterInterval.None, BP35UartFlowControl flowControl = BP35UartFlowControl.Disabled, CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartConfigurations uartConfigurations, CancellationToken cancellationToken = default) {}
public ValueTask SetUdpDataFormatAsync(BP35UdpReceiveDataFormat format, CancellationToken cancellationToken = default) {}
}
public readonly struct BP35UartConfigurations {
public BP35UartConfigurations(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval, BP35UartFlowControl flowControl) {}
public BP35UartBaudRate BaudRate { get; }
public BP35UartCharacterInterval CharacterInterval { get; }
public BP35UartFlowControl FlowControl { get; }
public void Deconstruct(out BP35UartBaudRate baudRate, out BP35UartCharacterInterval characterInterval, out BP35UartFlowControl flowControl) {}
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.4.1.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.3.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
diff --git a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-netstandard2.1.apilist.cs b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-netstandard2.1.apilist.cs
index e9184a4..1b92fd5 100644
--- a/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-netstandard2.1.apilist.cs
+++ b/doc/api-list/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX-netstandard2.1.apilist.cs
@@ -1,106 +1,99 @@
-// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-1.0.0)
+// Smdn.Devices.BP35XX.dll (Smdn.Devices.BP35XX-2.0.0)
// Name: Smdn.Devices.BP35XX
-// AssemblyVersion: 1.0.0.0
-// InformationalVersion: 1.0.0+e4163ada5b034b45c5cc0dac179b412cf54198cd
+// AssemblyVersion: 2.0.0.0
+// InformationalVersion: 2.0.0+ef185af5c73268aab02d6909202fffce4560122b
// TargetFramework: .NETStandard,Version=v2.1
// Configuration: Release
// Referenced assemblies:
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Smdn.Fundamental.PrintableEncoding.Hexadecimal, Version=3.0.0.0, Culture=neutral
// Smdn.Net.SkStackIP, Version=1.0.0.0, Culture=neutral
// System.IO.Ports, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
#nullable enable annotations
using System;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using Smdn.Devices.BP35XX;
using Smdn.Net.SkStackIP;
namespace Smdn.Devices.BP35XX {
- public interface IBP35Configurations {
- BP35UartBaudRate BaudRate { get; }
- SkStackERXUDPDataFormat ERXUDPDataFormat { get; }
- string? SerialPortName { get; }
- bool TryLoadFlashMemory { get; }
- }
-
- public interface IBP35SerialPortStreamFactory {
- Stream CreateSerialPortStream(IBP35Configurations configurations);
+ public interface IBP35SerialPortStreamFactory : IDisposable {
+ Stream CreateSerialPortStream(string? serialPortName);
}
public enum BP35UartBaudRate : byte {
Baud115200 = 0,
Baud19200 = 4,
Baud2400 = 1,
Baud38400 = 5,
Baud4800 = 2,
Baud57600 = 6,
Baud9600 = 3,
}
public enum BP35UartCharacterInterval : byte {
Microseconds100 = 16,
Microseconds200 = 32,
Microseconds300 = 48,
Microseconds400 = 64,
Microseconds50 = 80,
None = 0,
}
public enum BP35UartFlowControl : byte {
Disabled = 0,
Enabled = 128,
}
public enum BP35UdpReceiveDataFormat : byte {
Binary = 0,
HexAscii = 1,
}
public class BP35A1 : BP35Base {
public static ValueTask<BP35A1> CreateAsync(BP35A1Configurations configurations, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
public static ValueTask<BP35A1> CreateAsync(string? serialPortName, IServiceProvider? serviceProvider = null, CancellationToken cancellationToken = default) {}
}
- public sealed class BP35A1Configurations : IBP35Configurations {
+ public sealed class BP35A1Configurations {
public BP35A1Configurations() {}
public BP35UartBaudRate BaudRate { get; set; }
public string? SerialPortName { get; set; }
- SkStackERXUDPDataFormat IBP35Configurations.ERXUDPDataFormat { get; }
public bool TryLoadFlashMemory { get; set; }
+ public bool UseFlowControl { get; set; }
}
public abstract class BP35Base : SkStackClient {
public IPAddress LinkLocalAddress { get; }
public PhysicalAddress MacAddress { get; }
public string RohmPassword { get; }
public string RohmUserId { get; }
public string SkStackAppVersion { get; }
public Version SkStackVersion { get; }
public async ValueTask<BP35UartConfigurations> GetUartOptionsAsync(CancellationToken cancellationToken = default) {}
public async ValueTask<BP35UdpReceiveDataFormat> GetUdpDataFormatAsync(CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval = BP35UartCharacterInterval.None, BP35UartFlowControl flowControl = BP35UartFlowControl.Disabled, CancellationToken cancellationToken = default) {}
public ValueTask SetUartOptionsAsync(BP35UartConfigurations uartConfigurations, CancellationToken cancellationToken = default) {}
public ValueTask SetUdpDataFormatAsync(BP35UdpReceiveDataFormat format, CancellationToken cancellationToken = default) {}
}
public readonly struct BP35UartConfigurations {
public BP35UartConfigurations(BP35UartBaudRate baudRate, BP35UartCharacterInterval characterInterval, BP35UartFlowControl flowControl) {}
public BP35UartBaudRate BaudRate { get; }
public BP35UartCharacterInterval CharacterInterval { get; }
public BP35UartFlowControl FlowControl { get; }
public void Deconstruct(out BP35UartBaudRate baudRate, out BP35UartCharacterInterval characterInterval, out BP35UartFlowControl flowControl) {}
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.4.1.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.3.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
Full changes
Full changes in this release:
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX.csproj b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX.csproj
index 2551c0f..484e112 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX.csproj
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX.csproj
@@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;netstandard2.1</TargetFrameworks>
- <VersionPrefix>1.0.0</VersionPrefix>
+ <VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion> -->
<Nullable>enable</Nullable>
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs
index 29ceb35..aa3478e 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs
@@ -8,6 +8,8 @@ using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using Smdn.Net.SkStackIP;
+
namespace Smdn.Devices.BP35XX;
public class BP35A1 : BP35Base {
@@ -19,6 +21,14 @@ public class BP35A1 : BP35Base {
/// </remarks>
internal const BP35UartBaudRate DefaultValueForBP35UartBaudRate = BP35UartBaudRate.Baud115200;
+ /// <summary>
+ /// Refer to the initial value of the flow control for UART setting in the BP35A1.
+ /// </summary>
+ /// <remarks>
+ /// See 'BP35A1コマンドリファレンス 3.32. WUART (プロダクト設定コマンド)' for detailed specifications.
+ /// </remarks>
+ internal const bool DefaultValueForUseFlowControl = false;
+
public static ValueTask<BP35A1> CreateAsync(
string? serialPortName,
IServiceProvider? serviceProvider = null,
@@ -49,15 +59,33 @@ public class BP35A1 : BP35Base {
cancellationToken: cancellationToken
);
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BP35A1"/> class with specifying configurations.
+ /// </summary>
+ /// <param name="configurations">
+ /// A <see cref="BP35A1Configurations"/> that holds the configurations to the <see cref="BP35A1"/> instance.
+ /// </param>
+ /// <param name="serviceProvider">
+ /// The <see cref="IServiceProvider"/>.
+ /// This constructor overload attempts to get a service of <see cref="IBP35SerialPortStreamFactory"/>, to create an <see cref="System.IO.Ports.SerialPort"/>.
+ /// </param>
private BP35A1(
- IBP35Configurations configurations,
+ BP35A1Configurations configurations,
IServiceProvider? serviceProvider = null
)
: base(
- configurations: configurations,
- serialPortStreamFactory: serviceProvider?.GetService<IBP35SerialPortStreamFactory>(),
+ serialPortName: configurations.SerialPortName,
+#pragma warning disable CA2000
+ serialPortStreamFactory: serviceProvider?.GetService<IBP35SerialPortStreamFactory>() ?? new BP35A1SerialPortStreamFactory(configurations),
+#pragma warning restore CA2000
+ erxudpDataFormat: SkStackERXUDPDataFormat.Binary,
logger: serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<BP35A1>()
)
{
}
+
+ private class BP35A1SerialPortStreamFactory(BP35A1Configurations configurations) : SerialPortStreamFactory {
+ public override BP35UartBaudRate BaudRate { get; } = configurations.BaudRate;
+ public override bool UseFlowControl { get; } = configurations.UseFlowControl;
+ }
}
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1Configurations.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1Configurations.cs
index eeffe6a..6047596 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1Configurations.cs
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1Configurations.cs
@@ -1,18 +1,25 @@
// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
-using Smdn.Net.SkStackIP;
-
namespace Smdn.Devices.BP35XX;
-public sealed class BP35A1Configurations : IBP35Configurations {
- /// <inheritdoc cref="IBP35Configurations.SerialPortName"/>
+public sealed class BP35A1Configurations {
+ /// <summary>
+ /// Gets or sets the <see cref="string"/> value that holds the serial port name for communicating with the device that implements the SKSTACK-IP protocol.
+ /// </summary>
public string? SerialPortName { get; set; }
- /// <inheritdoc cref="IBP35Configurations.BaudRate"/>
+ /// <summary>
+ /// Gets or sets the <see cref="BP35UartBaudRate"/> value that specifies the baud rate of the serial port for communicating with the device.
+ /// </summary>
public BP35UartBaudRate BaudRate { get; set; } = BP35A1.DefaultValueForBP35UartBaudRate;
- /// <inheritdoc cref="IBP35Configurations.TryLoadFlashMemory"/>
- public bool TryLoadFlashMemory { get; set; } = BP35Base.DefaultValueForTryLoadFlashMemory;
+ /// <summary>
+ /// Gets or sets a value indicating whether or not to use the Request-to-Send (RTS) hardware flow control for communicating with the device.
+ /// </summary>
+ public bool UseFlowControl { get; set; } = BP35A1.DefaultValueForUseFlowControl;
- SkStackERXUDPDataFormat IBP35Configurations.ERXUDPDataFormat => SkStackERXUDPDataFormat.Binary;
+ /// <summary>
+ /// Gets or sets a value indicating whether or not to attempt to load the configuration from flash memory during initialization.
+ /// </summary>
+ public bool TryLoadFlashMemory { get; set; } = BP35Base.DefaultValueForTryLoadFlashMemory;
}
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.DefaultSerialPortStreamFactory.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.SerialPortStreamFactory.cs
similarity index 56%
rename from src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.DefaultSerialPortStreamFactory.cs
rename to src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.SerialPortStreamFactory.cs
index 2b62f11..c09a040 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.DefaultSerialPortStreamFactory.cs
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.SerialPortStreamFactory.cs
@@ -10,15 +10,21 @@ namespace Smdn.Devices.BP35XX;
#pragma warning disable IDE0040
partial class BP35Base {
#pragma warning restore IDE0040
- private class DefaultSerialPortStreamFactory : IBP35SerialPortStreamFactory {
- public static DefaultSerialPortStreamFactory Instance { get; } = new();
+ internal abstract class SerialPortStreamFactory : IBP35SerialPortStreamFactory {
+ public abstract BP35UartBaudRate BaudRate { get; }
+ public abstract bool UseFlowControl { get; }
- public Stream CreateSerialPortStream(IBP35Configurations configurations)
+ public void Dispose()
{
- if (string.IsNullOrEmpty(configurations.SerialPortName)) {
+ // nothing to do in this class
+ }
+
+ public Stream CreateSerialPortStream(string? serialPortName)
+ {
+ if (string.IsNullOrEmpty(serialPortName)) {
throw new ArgumentException(
- message: $"The {nameof(configurations.SerialPortName)} is not set for the {configurations.GetType().Name}",
- paramName: nameof(configurations)
+ message: $"The {nameof(serialPortName)} must be a non-empty string.",
+ paramName: nameof(serialPortName)
);
}
@@ -26,8 +32,8 @@ partial class BP35Base {
#pragma warning disable CA2000
var port = new SerialPort(
- portName: configurations.SerialPortName,
- baudRate: configurations.BaudRate switch {
+ portName: serialPortName,
+ baudRate: BaudRate switch {
BP35UartBaudRate.Baud2400 => 2_400,
BP35UartBaudRate.Baud4800 => 4_800,
BP35UartBaudRate.Baud9600 => 9_600,
@@ -35,18 +41,15 @@ partial class BP35Base {
BP35UartBaudRate.Baud38400 => 38_400,
BP35UartBaudRate.Baud57600 => 57_600,
BP35UartBaudRate.Baud115200 => 115_200,
- _ => throw new ArgumentException(
- message: $"A valid {nameof(BP35UartBaudRate)} value is not set for the {configurations.GetType().Name}",
- paramName: nameof(configurations)
- ),
+ _ => throw new InvalidOperationException($"A valid {nameof(BP35UartBaudRate)} value is not set for the {nameof(BaudRate)}"),
},
parity: Parity.None,
dataBits: 8,
stopBits: StopBits.One
) {
- Handshake = Handshake.None, // TODO: RequestToSend
+ Handshake = UseFlowControl ? Handshake.RequestToSend : Handshake.None,
DtrEnable = false,
- RtsEnable = false,
+ RtsEnable = UseFlowControl,
NewLine = CRLF,
};
#pragma warning restore CA2000
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.cs
index a498b91..3ffaf8c 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.cs
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35Base.cs
@@ -93,26 +93,28 @@ public abstract partial class BP35Base : SkStackClient {
/// <summary>
/// Initializes a new instance of the <see cref="BP35Base"/> class with specifying the serial port name.
/// </summary>
- /// <param name="configurations">
- /// A <see cref="IBP35Configurations"/> that holds the configurations to the <see cref="BP35Base"/> instance.
+ /// <param name="serialPortName">
+ /// A <see cref="string"/> that holds the serial port name to which <see cref="BP35Base"/> device is connected.
/// </param>
/// <param name="serialPortStreamFactory">
- /// A <see cref="IBP35SerialPortStreamFactory"/> that provides the function to create the serial port stream according to the <paramref name="configurations"/>.
+ /// A <see cref="IBP35SerialPortStreamFactory"/> that provides the function to create the serial port stream.
+ /// </param>
+ /// <param name="erxudpDataFormat">
+ /// A <see cref="SkStackERXUDPDataFormat"/> that specifies the format of the data part received in the event <c>ERXUDP</c>. See <see cref="SkStackClient.ERXUDPDataFormat"/>.
/// </param>
/// <param name="logger">The <see cref="ILogger"/> to report the situation.</param>
#pragma warning disable IDE0290
private protected BP35Base(
- IBP35Configurations configurations,
- IBP35SerialPortStreamFactory? serialPortStreamFactory,
+ string? serialPortName,
+ IBP35SerialPortStreamFactory serialPortStreamFactory,
+ SkStackERXUDPDataFormat erxudpDataFormat,
ILogger? logger
)
#pragma warning restore IDE0290
: base(
- stream: (serialPortStreamFactory ?? DefaultSerialPortStreamFactory.Instance).CreateSerialPortStream(
- configurations ?? throw new ArgumentNullException(nameof(configurations))
- ),
+ stream: (serialPortStreamFactory ?? throw new ArgumentNullException(nameof(serialPortStreamFactory))).CreateSerialPortStream(serialPortName),
leaveStreamOpen: false, // should close the opened stream
- erxudpDataFormat: configurations.ERXUDPDataFormat,
+ erxudpDataFormat: erxudpDataFormat,
logger: logger
)
{
@@ -124,6 +126,9 @@ public abstract partial class BP35Base : SkStackClient {
CancellationToken cancellationToken
)
{
+ // reset first before configuring
+ await SendSKRESETAsync(cancellationToken).ConfigureAwait(false);
+
// retrieve firmware version
skstackVersion = (await SendSKVERAsync(cancellationToken).ConfigureAwait(false)).Payload;
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35Configurations.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35Configurations.cs
deleted file mode 100644
index 457e941..0000000
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35Configurations.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
-// SPDX-License-Identifier: MIT
-using Smdn.Net.SkStackIP;
-
-namespace Smdn.Devices.BP35XX;
-
-public interface IBP35Configurations {
- /// <summary>
- /// Gets the <see cref="string"/> value that holds the serial port name for communicating with the device that implements the SKSTACK-IP protocol.
- /// </summary>
- string? SerialPortName { get; }
-
- /// <summary>
- /// Gets the <see cref="BP35UartBaudRate"/> value that specifies the baud rate of the serial port for communicating with the device.
- /// </summary>
- BP35UartBaudRate BaudRate { get; }
-
- /// <summary>
- /// Gets a value indicating whether or not to attempt to load the configuration from flash memory during initialization.
- /// </summary>
- bool TryLoadFlashMemory { get; }
-
- /// <summary>
- /// Gets the value that specifies the format of the data part received in the event <c>ERXUDP</c>. See <see cref="SkStackClient.ERXUDPDataFormat"/>.
- /// </summary>
- /// <seealso cref="SkStackClient.ERXUDPDataFormat"/>
- /// <seealso cref="SkStackERXUDPDataFormat"/>
- SkStackERXUDPDataFormat ERXUDPDataFormat { get; }
-}
diff --git a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35SerialPortStreamFactory.cs b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35SerialPortStreamFactory.cs
index b6a192f..34d08de 100644
--- a/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35SerialPortStreamFactory.cs
+++ b/src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/IBP35SerialPortStreamFactory.cs
@@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2024 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
+using System;
using System.IO;
namespace Smdn.Devices.BP35XX;
-public interface IBP35SerialPortStreamFactory {
- Stream CreateSerialPortStream(IBP35Configurations configurations);
+public interface IBP35SerialPortStreamFactory : IDisposable {
+ Stream CreateSerialPortStream(string? serialPortName);
}
Notes
Full Changelog: releases/Smdn.Devices.BP35XX-1.0.0...releases/Smdn.Devices.BP35XX-2.0.0