Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
- Fixes deadlock #20 #26
- Added `ReconnectDelay` property to get/set the reconnection delay in milliseconds - default = *1000* (closes #24)
  • Loading branch information
genemars committed Oct 4, 2023
1 parent ba9d65b commit baee442
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
24 changes: 0 additions & 24 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,3 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright (2012-2023) G-Labs (https://github.com/genielabs)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
2 changes: 1 addition & 1 deletion SerialPortLib.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of SerialPortLib (https://github.com/genielabs/serialport-lib-dotnet)
Copyright (2012-2018) G-Labs (https://github.com/genielabs)
Copyright (2012-2023) G-Labs (https://github.com/genielabs)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion SerialPortLib/Events.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of SerialPortLib (https://github.com/genielabs/serialport-lib-dotnet)
Copyright (2012-2018) G-Labs (https://github.com/genielabs)
Copyright (2012-2023) G-Labs (https://github.com/genielabs)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
23 changes: 20 additions & 3 deletions SerialPortLib/SerialPort.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of SerialPortLib (https://github.com/genielabs/serialport-lib-dotnet)
Copyright (2012-2018) G-Labs (https://github.com/genielabs)
Copyright (2012-2023) G-Labs (https://github.com/genielabs)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -124,7 +124,9 @@ public SerialPortInput()
public bool Connect()
{
if (_disconnectRequested)
{
return false;
}
lock (_accessLock)
{
Disconnect();
Expand All @@ -142,15 +144,19 @@ public bool Connect()
public void Disconnect()
{
if (_disconnectRequested)
{
return;
}
_disconnectRequested = true;
Close();
lock (_accessLock)
{
if (_connectionWatcher != null)
{
if (!_connectionWatcher.Join(5000))
{
_connectionWatcherCts.Cancel();
}
_connectionWatcher = null;
}
_disconnectRequested = false;
Expand Down Expand Up @@ -218,6 +224,11 @@ public bool SendMessage(byte[] message)
return success;
}

/// <summary>
/// Gets/Sets serial port reconnection delay in milliseconds.
/// </summary>
public int ReconnectDelay { get; set; } = 1000;

#endregion

#region Private members
Expand Down Expand Up @@ -356,8 +367,8 @@ private void ConnectionWatcherTask(object data)
try
{
Close();
// wait 1 sec before reconnecting
Thread.Sleep(1000);
// wait "ReconnectDelay" seconds before reconnecting
Thread.Sleep(ReconnectDelay);
if (!_disconnectRequested)
{
try
Expand All @@ -376,7 +387,9 @@ private void ConnectionWatcherTask(object data)
}
}
if (!_disconnectRequested)
{
Thread.Sleep(1000);
}
}
}

Expand Down Expand Up @@ -407,7 +420,9 @@ protected virtual void OnConnectionStatusChanged(ConnectionStatusChangedEventArg
{
LogDebug(args.Connected.ToString());
if (ConnectionStatusChanged != null)
{
ConnectionStatusChanged(this, args);
}
}

/// <summary>
Expand All @@ -418,7 +433,9 @@ protected virtual void OnMessageReceived(MessageReceivedEventArgs args)
{
LogDebug(BitConverter.ToString(args.Data));
if (MessageReceived != null)
{
MessageReceived(this, args);
}
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion SerialPortLib/nuget_pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (-not ([string]::IsNullOrEmpty($versionStr))) {

$content | Out-File $root\$project\$project.csproj

& dotnet pack $root\$project -o .
& dotnet pack -c release $root\$project -o .
}
else {
Write-Host "Version string is empty, possibly dry run or APPVEYOR_REPO_TAG_NAME environment variable is not set"
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ after_test:
artifacts:
- path: '*.nupkg'
name: SerialPortLib nupkg
type: NuGetPackage
deploy:
- provider: GitHub
auth_token:
Expand Down

0 comments on commit baee442

Please sign in to comment.