diff --git a/Samples/BuzzerTest/BuzzerTest.csproj b/Samples/BuzzerTest/BuzzerTest.csproj
index 62c0a75..6878d4c 100644
--- a/Samples/BuzzerTest/BuzzerTest.csproj
+++ b/Samples/BuzzerTest/BuzzerTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -16,4 +16,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
+ <ItemGroup>
+ <Compile Remove="OutputPort.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
+ </ItemGroup>
+
</Project>
diff --git a/Samples/BuzzerTest/Program.cs b/Samples/BuzzerTest/Program.cs
index 5cc76c7..15c1a5c 100644
--- a/Samples/BuzzerTest/Program.cs
+++ b/Samples/BuzzerTest/Program.cs
@@ -1,6 +1,6 @@
-using SmartA2;
+using NewLife.IoT.Controllers;
-var buzzer = new OutputPort { FileName = "/dev/buzzer" };
+var buzzer = new FileOutputPort("/dev/buzzer");
for (var i = 0; i < 5; i++)
{
diff --git a/Samples/DatabaseTest/DatabaseTest.csproj b/Samples/DatabaseTest/DatabaseTest.csproj
index 62bcd22..d2f71e4 100644
--- a/Samples/DatabaseTest/DatabaseTest.csproj
+++ b/Samples/DatabaseTest/DatabaseTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.XCode" Version="11.10.2023.1012" />
+ <PackageReference Include="NewLife.XCode" Version="11.10.2023.1201" />
</ItemGroup>
</Project>
diff --git a/Samples/KeyTest/KeyTest.csproj b/Samples/KeyTest/KeyTest.csproj
index fd3f49b..e8ae198 100644
--- a/Samples/KeyTest/KeyTest.csproj
+++ b/Samples/KeyTest/KeyTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -16,4 +16,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
+ <ItemGroup>
+ <Compile Remove="InputPort.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
+ </ItemGroup>
+
</Project>
diff --git a/Samples/KeyTest/Program.cs b/Samples/KeyTest/Program.cs
index d3822a9..66165e9 100644
--- a/Samples/KeyTest/Program.cs
+++ b/Samples/KeyTest/Program.cs
@@ -1,6 +1,6 @@
-using SmartA2;
+using NewLife.IoT.Controllers;
-var key = new InputPort { FileName = "/dev/key" };
+var key = new FileInputPort("/dev/key");
var f = false;
for (var i = 0; i < 100; i++)
diff --git a/Samples/LedTest/LedTest.csproj b/Samples/LedTest/LedTest.csproj
index 340b958..e267f21 100644
--- a/Samples/LedTest/LedTest.csproj
+++ b/Samples/LedTest/LedTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -16,4 +16,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
+ <ItemGroup>
+ <Compile Remove="OutputPort.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
+ </ItemGroup>
+
</Project>
diff --git a/Samples/LedTest/Program.cs b/Samples/LedTest/Program.cs
index ffc1766..6bdafe2 100644
--- a/Samples/LedTest/Program.cs
+++ b/Samples/LedTest/Program.cs
@@ -1,6 +1,6 @@
-using SmartA2;
+using NewLife.IoT.Controllers;
-var led = new OutputPort { FileName = "/dev/led" };
+var led = new FileOutputPort("/dev/led");
while (true)
{
diff --git a/Samples/NetClientTest/NetClientTest.csproj b/Samples/NetClientTest/NetClientTest.csproj
index a307fdd..8f4ef61 100644
--- a/Samples/NetClientTest/NetClientTest.csproj
+++ b/Samples/NetClientTest/NetClientTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
+ <PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
</ItemGroup>
</Project>
diff --git a/Samples/NetServerTest/NetServerTest.csproj b/Samples/NetServerTest/NetServerTest.csproj
index 6d3003d..db353fc 100644
--- a/Samples/NetServerTest/NetServerTest.csproj
+++ b/Samples/NetServerTest/NetServerTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
+ <PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
</ItemGroup>
</Project>
diff --git a/Samples/Serial2NetClientTest/Serial2NetClientTest.csproj b/Samples/Serial2NetClientTest/Serial2NetClientTest.csproj
index 11ea5b9..2d54860 100644
--- a/Samples/Serial2NetClientTest/Serial2NetClientTest.csproj
+++ b/Samples/Serial2NetClientTest/Serial2NetClientTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
+ <PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
</ItemGroup>
<ItemGroup>
diff --git a/Samples/Serial2NetServerTest/Serial2NetServerTest.csproj b/Samples/Serial2NetServerTest/Serial2NetServerTest.csproj
index 55a8f17..ef06ac2 100644
--- a/Samples/Serial2NetServerTest/Serial2NetServerTest.csproj
+++ b/Samples/Serial2NetServerTest/Serial2NetServerTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
+ <PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
</ItemGroup>
</Project>
diff --git a/Samples/SerialTest/SerialTest.csproj b/Samples/SerialTest/SerialTest.csproj
index f89adb3..39b2e32 100644
--- a/Samples/SerialTest/SerialTest.csproj
+++ b/Samples/SerialTest/SerialTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -17,7 +17,8 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
+ <PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
</ItemGroup>
<ItemGroup>
diff --git a/Samples/UsbPowerTest/Program.cs b/Samples/UsbPowerTest/Program.cs
index b5961a0..f960906 100644
--- a/Samples/UsbPowerTest/Program.cs
+++ b/Samples/UsbPowerTest/Program.cs
@@ -1,7 +1,7 @@
-using SmartA2;
+using NewLife.IoT.Controllers;
// USB口电源控制,可用于控制外部USB设备上电。如风扇、灯光、水泵等
-var usb = new OutputPort { FileName = "/dev/usbpwr" };
+var usb = new FileOutputPort("/dev/usbpwr");
// 上电
usb.Write(true);
diff --git a/Samples/UsbPowerTest/UsbPowerTest.csproj b/Samples/UsbPowerTest/UsbPowerTest.csproj
index a7aa338..0fd0fb9 100644
--- a/Samples/UsbPowerTest/UsbPowerTest.csproj
+++ b/Samples/UsbPowerTest/UsbPowerTest.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 新生命开发团队</Copyright>
<VersionPrefix>1.0</VersionPrefix>
@@ -16,4 +16,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
+ <ItemGroup>
+ <Compile Remove="OutputPort.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
+ </ItemGroup>
+
</Project>
diff --git a/SmartA2/A2.cs b/SmartA2/A2.cs
index 1fd73f0..fb1d9b6 100644
--- a/SmartA2/A2.cs
+++ b/SmartA2/A2.cs
@@ -1,7 +1,6 @@
using System.ComponentModel;
-using System.IO.Ports;
using NewLife;
-using NewLife.IoT.Protocols;
+using NewLife.IoT.Controllers;
using NewLife.Serial.Protocols;
namespace SmartA2;
@@ -23,51 +22,88 @@ public enum Coms
}
/// <summary>A2硬件工厂</summary>
-public class A2
+public class A2 : Board
{
#region 属性
/// <summary>SYS LED 指示灯</summary>
[DisplayName("指示灯")]
- public OutputPort Led { get; } = new OutputPort { FileName = "/dev/led" };
+ public IOutputPort Led { get; } = new FileOutputPort("/dev/led");
/// <summary>蜂鸣器</summary>
[DisplayName("蜂鸣器")]
- public OutputPort Buzzer { get; } = new OutputPort { FileName = "/dev/buzzer" };
+ public IOutputPort Buzzer { get; } = new FileOutputPort("/dev/buzzer");
/// <summary>FUN按键</summary>
[DisplayName("FUN按键")]
- public InputPort Key { get; } = new InputPort { FileName = "/dev/key" };
+ public IInputPort Key { get; } = new FileInputPort("/dev/key");
/// <summary>USB电源</summary>
[DisplayName("USB电源")]
- public OutputPort UsbPower { get; } = new OutputPort { FileName = "/dev/usbpwr" };
+ public IOutputPort UsbPower { get; } = new FileOutputPort("/dev/usbpwr");
/// <summary>看门狗</summary>
public Watchdog Watchdog { get; } = new Watchdog { FileName = "/dev/watchdog" };
/// <summary>串口名</summary>
- public String[] ComNames = new[] { "/dev/ttyAMA0", "/dev/ttyAMA1", "/dev/ttyAMA2", "/dev/ttyAMA3" };
+ public String[] ComNames = ["/dev/ttyAMA0", "/dev/ttyAMA1", "/dev/ttyAMA2", "/dev/ttyAMA3"];
+ #endregion
+
+ #region 端口
+ /// <summary>创建输出口</summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public override IOutputPort CreateOutput(String name)
+ {
+ if (name.EndsWithIgnoreCase("led")) return Led;
+ if (name.EndsWithIgnoreCase("buzzer")) return Buzzer;
+ if (name.EndsWithIgnoreCase("usbpwr")) return UsbPower;
+
+ return base.CreateOutput(name);
+ }
+
+ /// <summary>创建输入口</summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public override IInputPort CreateInput(String name)
+ {
+ if (name.EndsWithIgnoreCase("key")) return Key;
+
+ return base.CreateInput(name);
+ }
#endregion
#region 串口
/// <summary>创建串口</summary>
+ /// <param name="portName"></param>
+ /// <param name="baudrate"></param>
+ /// <returns></returns>
+ public override ISerialPort CreateSerial(String portName, Int32 baudrate = 9600) => new DefaultSerialPort { PortName = portName, Baudrate = baudrate };
+
+ /// <summary>创建串口</summary>
/// <param name="com">串口COM1/COM2/COM3/COM4,全部支持RS485,其中COM3/COM4复用RS232</param>
/// <param name="baudrate"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
- public SerialPort CreateSerial(Coms com, Int32 baudrate = 9600)
+ public ISerialPort CreateSerial(Coms com, Int32 baudrate = 9600)
{
if (com < 0 || com > Coms.COM4) throw new ArgumentOutOfRangeException(nameof(com), $"无效串口{com},支持COM1/COM2/COM3/COM4");
- return new SerialPort(ComNames[(Int32)com], baudrate);
+ //return new SerialPort(ComNames[(Int32)com], baudrate);
+ return new DefaultSerialPort { PortName = ComNames[(Int32)com], Baudrate = baudrate };
}
/// <summary>创建Modbus</summary>
+ /// <param name="portName"></param>
+ /// <param name="baudrate"></param>
+ /// <returns></returns>
+ public override IModbus CreateModbus(String portName, Int32 baudrate = 9600) => new ModbusRtu { PortName = portName, Baudrate = baudrate };
+
+ /// <summary>创建Modbus</summary>
/// <param name="com"></param>
/// <param name="baudrate"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
- public Modbus CreateModbus(Coms com, Int32 baudrate = 9600)
+ public IModbus CreateModbus(Coms com, Int32 baudrate = 9600)
{
if (com < 0 || com > Coms.COM4) throw new ArgumentOutOfRangeException(nameof(com), $"无效串口{com},支持COM1/COM2/COM3/COM4");
diff --git a/SmartA2/Drivers/A2Driver.cs b/SmartA2/Drivers/A2Driver.cs
index 1a17178..b14404d 100644
--- a/SmartA2/Drivers/A2Driver.cs
+++ b/SmartA2/Drivers/A2Driver.cs
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Reflection;
using NewLife;
+using NewLife.IoT.Controllers;
using NewLife.IoT.Drivers;
using NewLife.IoT.ThingModels;
using NewLife.IoT.ThingSpecification;
@@ -55,9 +56,9 @@ public class A2Driver : DriverBase<Node, PCParameter>
if (point != null)
{
var val = _a2.GetValue(pi);
- if (val is InputPort inputPort)
+ if (val is IInputPort inputPort)
dic[point.Name] = inputPort.Read();
- else if (val is OutputPort outputPort)
+ else if (val is IOutputPort outputPort)
dic[point.Name] = outputPort.Read();
}
}
@@ -161,14 +162,14 @@ public class A2Driver : DriverBase<Node, PCParameter>
// A2特有
foreach (var pi in _a2.GetType().GetProperties())
{
- if (pi.PropertyType == typeof(InputPort))
+ if (pi.PropertyType == typeof(IInputPort))
{
var pt = PropertySpec.Create(pi);
pt.DataType.Type = "bool";
pt.AccessMode = "r";
points.Add(pt);
}
- else if (pi.PropertyType == typeof(OutputPort))
+ else if (pi.PropertyType == typeof(IOutputPort))
{
var pt = PropertySpec.Create(pi);
pt.DataType.Type = "bool";
diff --git a/SmartA2/SmartA2.csproj b/SmartA2/SmartA2.csproj
index 3dec190..a4ed689 100644
--- a/SmartA2/SmartA2.csproj
+++ b/SmartA2/SmartA2.csproj
@@ -37,15 +37,20 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
+ <Compile Remove="InputPort.cs" />
+ <Compile Remove="OutputPort.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
- <PackageReference Include="NewLife.IoT" Version="1.9.2023.1001" />
- <PackageReference Include="NewLife.ModbusRTU" Version="1.6.2023.711-beta1735" />
+ <PackageReference Include="NewLife.IoT" Version="2.0.2023.1210-beta1616" />
+ <PackageReference Include="NewLife.ModbusRTU" Version="1.8.2023.1210-beta1629" />
</ItemGroup>
<ItemGroup>
diff --git a/Test/Test.csproj b/Test/Test.csproj
index 728c42a..c00fda3 100644
--- a/Test/Test.csproj
+++ b/Test/Test.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<OutputPath>..\Bin\Test</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ImplicitUsings>enable</ImplicitUsings>
diff --git a/XUnitTest/XUnitTest.csproj b/XUnitTest/XUnitTest.csproj
index e086d1f..85f88df 100644
--- a/XUnitTest/XUnitTest.csproj
+++ b/XUnitTest/XUnitTest.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>net7.0</TargetFramework>
+ <TargetFramework>net8.0</TargetFramework>
<OutputPath>..\Bin\UnitTest</OutputPath>
<ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>-->
@@ -10,11 +10,11 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
- <PackageReference Include="NewLife.UnitTest" Version="1.0.2023.905" />
- <PackageReference Include="System.Speech" Version="7.0.0" />
- <PackageReference Include="xunit" Version="2.5.3" />
- <PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
+ <PackageReference Include="NewLife.UnitTest" Version="1.0.2023.1204" />
+ <PackageReference Include="System.Speech" Version="8.0.0" />
+ <PackageReference Include="xunit" Version="2.6.3" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>