Skip to content

Commit 65858da

Browse files
committed
修复Linux系统下串口客户端连接字符串中不能带/dev前缀的问题。
1 parent 9e0d2b1 commit 65858da

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

QpTestClient/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using System.Windows.Forms;
63

74
namespace QpTestClient

Quick.Protocol.SerialPort/QpSerialPortClientOptions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public partial class QpSerialPortClientOptionsSerializerContext : JsonSerializer
1313
public class QpSerialPortClientOptions : QpClientOptions
1414
{
1515
protected override JsonSerializerContext GetJsonSerializerContext() => QpSerialPortClientOptionsSerializerContext.Default;
16+
private const string unixPortNamePrefix = "/dev/";
1617

1718
public const string URI_SCHEMA = "qp.serial";
1819
/// <summary>
@@ -73,13 +74,24 @@ protected override void LoadFromQueryString(string key, string value)
7374
protected override void LoadFromUri(Uri uri)
7475
{
7576
PortName = uri.Host;
77+
if (!OperatingSystem.IsWindows())
78+
{
79+
if (!PortName.StartsWith(unixPortNamePrefix))
80+
PortName = unixPortNamePrefix + PortName;
81+
}
7682
base.LoadFromUri(uri);
7783
}
7884

7985
protected override string ToUriBasic(HashSet<string> ignorePropertyNames)
8086
{
8187
ignorePropertyNames.Add(nameof(PortName));
82-
return $"{URI_SCHEMA}://{PortName}";
88+
var host = PortName;
89+
if (!OperatingSystem.IsWindows())
90+
{
91+
if (host.StartsWith(unixPortNamePrefix))
92+
host = host.Substring(unixPortNamePrefix.Length);
93+
}
94+
return $"{URI_SCHEMA}://{host}";
8395
}
8496

8597
public static void RegisterUriSchema()

Quick.Protocol.SerialPort/Quick.Protocol.SerialPort.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -22,7 +22,7 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="System.IO.Ports" Version="9.0.0" />
25+
<PackageReference Include="System.IO.Ports" Version="9.0.6" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

Quick.Protocol/Quick.Protocol.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -23,6 +23,6 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" />
26+
<PackageReference Include="System.IO.Pipelines" Version="9.0.6" />
2727
</ItemGroup>
2828
</Project>

0 commit comments

Comments
 (0)