MasterServer.Lib.Plc
1.0.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MasterServer.Lib.Plc --version 1.0.7
NuGet\Install-Package MasterServer.Lib.Plc -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MasterServer.Lib.Plc" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasterServer.Lib.Plc" Version="1.0.7" />
<PackageReference Include="MasterServer.Lib.Plc" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MasterServer.Lib.Plc --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MasterServer.Lib.Plc, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MasterServer.Lib.Plc@1.0.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MasterServer.Lib.Plc&version=1.0.7
#tool nuget:?package=MasterServer.Lib.Plc&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Automation.Lib.Plc
PLC通信基础库,提供统一的PLC数据访问接口和配置管理。
特性
- 统一的PLC通信抽象层
- 支持数据项和数组操作
- Reactive流支持数据变化通知
- XML配置支持
- 自动连接管理和重连
- 支持多种数据类型(bool, short, int, float, double(包括他们的数组), string等)
- 线程安全的异步操作
核心组件
1. BasePlcConfig
PLC配置基类,提供连接信息管理和数据项初始化。
2. DataItem<T>
单个数据项操作类,支持:
- 读写操作
- 数据变化订阅
- 轮询监控
3. ArrayNode<T>
数组数据操作类,支持:
- 批量读写
- 数据变化检测
- Reactive流
4. ConnectInfo
连接信息基类,包含IP、端口、超时等配置。
使用方式
1. 定义PLC配置(案例)
using Automation.Lib.Plc;
public class PlcConfig : BasePlcConfig
{
/// <summary>
/// 心跳
/// </summary>
[XmlElement]
public DataItem<short> Heartbeat { get; set; }
//**************************下面是单个数**********************************//
[XmlElement]
public DataItem<short> TestShort { get; set; }
[XmlElement]
public DataItem<float> TestFloat { get; set; }
[XmlElement]
public DataItem<bool> TestBool { get; set; }
//********************************下面是数组******************************//
[XmlElement]
public ArrayNode<short> TestShortArray { get; set; }
[XmlElement]
public ArrayNode<float> TestFloatArray { get; set; }
[XmlElement]
public ArrayNode<float> TestFloatArray2 { get; set; }
[XmlElement]
public ArrayNode<bool> TestBoolArray { get; set; }
[XmlElement]
public DataItem<string> TestString { get; set; }
2. 连接和操作
string ConfigDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config");
Installer.Install("S7Net");//根据连接协议的不同,做出对应的修改
XmlSerializer ser = new XmlSerializer(typeof(PlcConfig), Installer.ExtraXmlTypes.ToArray());
using (var reader = new StreamReader(Path.Combine(ConfigDir, "PlcConfig.xml")))
{
string xml = reader.ReadToEnd();
PlcConfig = Serializer.FromXml<PlcConfig>(xml, ser);
}
PlcConfig.InitializeArrayNodes();
// 读取数据
short value = PlcConfig.TestShort.Read();
// 写入数据
PlcConfig.TestShort.Write(123);
// 订阅数据变化
plcConfig.TestShortArray.StartPolling(TimeSpan.FromMilliseconds(200));//开始轮询
plcConfig.TestShortArray.DataChanged.Subscribe(newValue =>
{
Console.WriteLine($"数据变化: {newValue}");
});
3. 数组操作
// 读取数组
float[] values = plcConfig.MyArray.Read();
// 写入数组(参数也可以用List<T>)
plcConfig.MyArray.Write(new float[] { 1.0f, 2.0f, 3.0f });
4. xml样例
<?xml version="1.0" encoding="utf-8"?>
<PlcConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Connection xsi:type="S7ConnectInfo">
<Id>plc1</Id>
<Address>127.0.0.1</Address>
<CpuType>S71200</CpuType>
<TimeOut>5000</TimeOut>
<ReConnectSeconds>3</ReConnectSeconds>
</Connection>
<Heartbeat xsi:type="S7ItemOfInt16" StartAddress="40" />
<TestShort xsi:type="S7ItemOfInt16" StartAddress="1" />
<TestFloat xsi:type="S7ItemOfSingle" StartAddress="2" />
<TestBool xsi:type="S7ItemOfBoolean" StartAddress="4" BitAdr="3" />
<TestShortArray xsi:type="S7ArrayOfInt16" StartAddress="5">
<DataItem xsi:type="S7ItemOfInt16" Name="x" Index="0" />
<DataItem xsi:type="S7ItemOfInt16" Name="y" Index="1" />
<DataItem xsi:type="S7ItemOfInt16" Name="z" Index="2" />
</TestShortArray>
<TestFloatArray xsi:type="S7ArrayOfSingle" StartAddress="8">
<DataItem xsi:type="S7ItemOfSingle" Name="x" Index="0" />
<DataItem xsi:type="S7ItemOfSingle" Name="y" Index="1" />
<DataItem xsi:type="S7ItemOfSingle" Name="z" Index="2" />
</TestFloatArray>
<TestBoolArray xsi:type="S7ArrayOfBoolean" StartAddress="16">
<DataItem xsi:type="S7ItemOfBoolean" Name="x" Index="0" />
<DataItem xsi:type="S7ItemOfBoolean" Name="y" Index="1" />
<DataItem xsi:type="S7ItemOfBoolean" Name="z" Index="2" />
</TestBoolArray>
<TestString xsi:type="S7ItemOfString" StartAddress="1" StringLength="20" />
</PlcConfig>
安装
通过NuGet安装:
Install-Package Automation.Lib.Plc
依赖
- System.Reactive
- System.Xml.Serialization</content>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- MasterServer.Lib.Logging (>= 1.0.1)
- System.Reactive (>= 6.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on MasterServer.Lib.Plc:
| Package | Downloads |
|---|---|
|
MasterServer.Lib.Plc.S7Net
bug修改 |
|
|
MasterServer.Lib.Plc.Modbus
命名空间和包名称统一,引用的包更新至最新稳定版 |
|
|
MasterServer.Lib.Plc.Opc
命名空间和包名称统一,引用的包更新至最新稳定版 |
|
|
MasterServer.Lib.Plc.Mc
bug修改 |
GitHub repositories
This package is not used by any popular GitHub repositories.