Skip to content

Commit 7859d2b

Browse files
Fix SerialPort Dispose warning (#99)
***NO_CI***
1 parent c0c065f commit 7859d2b

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

System.IO.Ports/SerialPort.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ internal static SerialPort FindDevice(int index)
783783
/// <exception cref="IOException">The port is in an invalid state. -or- An attempt to set the state of the underlying
784784
/// port failed. For example, the parameters passed from this <see cref="SerialPort"/>
785785
/// object were invalid.</exception>
786-
protected void Dispose(bool disposing)
786+
internal void Dispose(bool disposing)
787787
{
788788
if (!_disposed)
789789
{

System.IO.Ports/System.IO.Ports.nfproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@
8080
<ProjectConfigurationsDeclaredAsItems />
8181
</ProjectCapabilities>
8282
</ProjectExtensions>
83-
<Import Project="..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" />
83+
<Import Project="..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets')" />
8484
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
8585
<PropertyGroup>
8686
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
8787
</PropertyGroup>
88-
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets'))" />
88+
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets'))" />
8989
</Target>
9090
</Project>

System.IO.Ports/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
55
<package id="nanoFramework.System.IO.Streams" version="1.1.9" targetFramework="netnanoframework10" />
66
<package id="nanoFramework.System.Text" version="1.2.3" targetFramework="netnanoframework10" />
7-
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
7+
<package id="Nerdbank.GitVersioning" version="3.5.107" targetFramework="netnanoframework10" developmentDependency="true" />
88
</packages>

Tests/UnitTestsSerialPort/SerialTests.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public class SerialTests
2323
[Setup]
2424
public void SetupComPorts()
2525
{
26+
OutputHelper.WriteLine("Setting up tests for an ESP32...");
2627
try
2728
{
28-
Debug.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");
29+
OutputHelper.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");
2930
Configuration.SetPinFunction(32, DeviceFunction.COM2_RX);
3031
Configuration.SetPinFunction(33, DeviceFunction.COM2_TX);
3132
Configuration.SetPinFunction(12, DeviceFunction.COM2_RTS);
@@ -36,22 +37,23 @@ public void SetupComPorts()
3637
Configuration.SetPinFunction(27, DeviceFunction.COM3_RTS);
3738
Configuration.SetPinFunction(14, DeviceFunction.COM3_CTS);
3839

39-
Debug.WriteLine("You will need to connect:");
40-
Debug.WriteLine(" COM2 RX <-> COM3 TX");
41-
Debug.WriteLine(" COM2 TX <-> COM3 RX");
42-
Debug.WriteLine(" COM2 RTS <-> COM3 CTS");
43-
Debug.WriteLine(" COM2 CTS <-> COM3 RTS");
40+
OutputHelper.WriteLine("You will need to connect:");
41+
OutputHelper.WriteLine(" COM2 RX <-> COM3 TX");
42+
OutputHelper.WriteLine(" COM2 TX <-> COM3 RX");
43+
OutputHelper.WriteLine(" COM2 RTS <-> COM3 CTS");
44+
OutputHelper.WriteLine(" COM2 CTS <-> COM3 RTS");
4445
_serOne = new SerialPort("COM2");
4546
_serTwo = new SerialPort("COM3");
46-
Debug.WriteLine("Devices created, trying to open them");
47+
OutputHelper.WriteLine("SerialPorts created, trying to open them");
4748
_serOne.Open();
48-
Debug.WriteLine("Serial One COM2 opened");
49+
OutputHelper.WriteLine("SerialPort One COM2 opened.");
4950
_serTwo.Open();
50-
Debug.WriteLine("Devices opened, will close them");
51-
// Wait a bit just to make sure and close them again
51+
OutputHelper.WriteLine("SerialPort Two COM3 opened.");
52+
OutputHelper.WriteLine("All SerialPorts opened, will close them");
53+
// Wait a bit just to make sure and close them all
5254
Thread.Sleep(100);
53-
_serOne.Close();
54-
_serTwo.Close();
55+
EnsurePortsClosed();
56+
OutputHelper.WriteLine("SerialPorts Closed.");
5557
}
5658
catch
5759
{
@@ -63,10 +65,10 @@ public void SetupComPorts()
6365
public void GetPortNamesTest()
6466
{
6567
var ports = SerialPort.GetPortNames();
66-
Debug.WriteLine("Available ports:");
68+
OutputHelper.WriteLine("Available SerialPorts:");
6769
foreach (string port in ports)
6870
{
69-
Debug.WriteLine($" {port}");
71+
OutputHelper.WriteLine($" {port}");
7072
}
7173
}
7274

0 commit comments

Comments
 (0)