Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
initial support for serial port on FreeBSD (#42519)
Browse files Browse the repository at this point in the history
* initial support for serial port on FreeBSD

* adjust port name selection

* update packaging

* feedback from review

* fix PortHelper

* update include with AnyOS
  • Loading branch information
wfurt authored Nov 14, 2019
1 parent d9dd0da commit 7a4822f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/System.IO.Ports/src/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
netstandard2.0-Windows_NT;
netstandard2.0-Linux;
netstandard2.0-OSX;
netstandard2.0-FreeBSD;
netstandard2.0;
net461-Windows_NT;
</PackageConfigurations>
Expand Down
11 changes: 7 additions & 4 deletions src/System.IO.Ports/src/System.IO.Ports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPartialFacadeAssembly Condition="'$(TargetsNetFx)' == 'true'">true</IsPartialFacadeAssembly>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsNetStandard)' == 'true' and '$(TargetsWindows)' != 'true' and '$(TargetsLinux)' != 'true' and '$(TargetsOSX)' != 'true'">SR.PlatformNotSupported_IOPorts</GeneratePlatformNotSupportedAssemblyMessage>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsNetStandard)' == 'true' and '$(OSGroup)' == 'AnyOS'">SR.PlatformNotSupported_IOPorts</GeneratePlatformNotSupportedAssemblyMessage>
<DefineConstants>$(DefineConstants);NOSPAN</DefineConstants>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<Configurations>net461-Windows_NT-Debug;net461-Windows_NT-Release;netfx-Windows_NT-Debug;netfx-Windows_NT-Release;netstandard2.0-Debug;netstandard2.0-Linux-Debug;netstandard2.0-Linux-Release;netstandard2.0-OSX-Debug;netstandard2.0-OSX-Release;netstandard2.0-Release;netstandard2.0-Windows_NT-Debug;netstandard2.0-Windows_NT-Release</Configurations>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsNetFx)' != 'true' and ('$(TargetsWindows)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true')">
<ItemGroup Condition="'$(TargetsNetStandard)' == 'true' and '$(OSGroup)' != 'AnyOS'">
<Compile Include="System\IO\Ports\Handshake.cs" />
<Compile Include="System\IO\Ports\InternalResources.cs" />
<Compile Include="System\IO\Ports\Parity.cs" />
Expand Down Expand Up @@ -145,7 +145,10 @@
<ItemGroup Condition=" '$(TargetsOSX)' == 'true' ">
<Compile Include="System\IO\Ports\SerialPort.OSX.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true'">
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true' ">
<Compile Include="System\IO\Ports\SerialPort.FreeBSD.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsFreeBSD)' == 'true'">
<Compile Include="System\IO\Ports\SafeSerialDeviceHandle.Unix.cs" />
<Compile Include="System\IO\Ports\SerialStream.Unix.cs" />
<Compile Include="Interop\Unix\Interop.Termios.cs" />
Expand Down Expand Up @@ -199,4 +202,4 @@
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
</ItemGroup>
</Project>
</Project>
37 changes: 37 additions & 0 deletions src/System.IO.Ports/src/System/IO/Ports/SerialPort.FreeBSD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;

namespace System.IO.Ports
{
public partial class SerialPort : Component
{
public static string[] GetPortNames()
{
List<string> ports = new List<string>();

foreach (string name in Directory.GetFiles("/dev", "ttyd*"))
{
if (!name.EndsWith(".init") && !name.EndsWith(".lock"))
{
ports.Add(name);
}
}

foreach (string name in Directory.GetFiles("/dev", "cuau*"))
{
if (!name.EndsWith(".init") && !name.EndsWith(".lock"))
{
ports.Add(name);
}
}

return ports.ToArray();
}
}
}
1 change: 1 addition & 0 deletions src/System.IO.Ports/tests/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
netcoreapp-Windows_NT;
netcoreapp-Linux;
netcoreapp-OSX;
netcoreapp-FreeBSD;
netfx;
</BuildConfigurations>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/System.IO.Ports/tests/Support/PortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PortHelper

public static string[] GetPorts()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
if (!PlatformDetection.IsWindows)
{
return SerialPort.GetPortNames();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
</BuildRID>
<BuildRID Include="linux-x64" />
<BuildRID Include="osx-x64" />
<BuildRID Include="freebsd-x64" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<SkipPackageFileCheck>true</SkipPackageFileCheck>
<SkipValidatePackage>true</SkipValidatePackage>
</PropertyGroup>
<ItemGroup Condition="'$(PackageTargetRuntime)' == 'linux-arm' or '$(PackageTargetRuntime)' == 'linux-arm64' or '$(PackageTargetRuntime)' == 'linux-x64' or '$(PackageTargetRuntime)' == 'osx-x64'">
<ItemGroup Condition="'$(PackageTargetRuntime)' == 'linux-arm' or '$(PackageTargetRuntime)' == 'linux-arm64' or '$(PackageTargetRuntime)' == 'linux-x64' or '$(PackageTargetRuntime)' == 'osx-x64' or '$(PackageTargetRuntime)' == 'freebsd-x64'">
<File Include="$(NativeBinDir)\System.IO.Ports.Native$(LibraryFileExtension)" >
<TargetPath>runtimes/$(PackageRID)/native</TargetPath>
</File>
Expand Down

0 comments on commit 7a4822f

Please sign in to comment.