MasterServer.Lib.Plc.Mc 2.0.1

dotnet add package MasterServer.Lib.Plc.Mc --version 2.0.1
                    
NuGet\Install-Package MasterServer.Lib.Plc.Mc -Version 2.0.1
                    
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.Mc" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasterServer.Lib.Plc.Mc" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MasterServer.Lib.Plc.Mc" />
                    
Project file
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.Mc --version 2.0.1
                    
#r "nuget: MasterServer.Lib.Plc.Mc, 2.0.1"
                    
#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.Mc@2.0.1
                    
#: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.Mc&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MasterServer.Lib.Plc.Mc&version=2.0.1
                    
Install as a Cake Tool

MasterServer.Lib.Plc.Mc

概述

该项目提供了对三菱 PLC MC 协议的支持,当前基于 McpX 实现与 PLC 的通信。支持单值和连续地址数组的读写,并保持与现有 PLC 抽象层一致的调用方式。

功能特性

支持的数据类型

  • 布尔型 (bool): 用于开关量、状态量
  • 短整型 (short): 16位有符号整数
  • 无符号短整型 (ushort): 16位无符号整数
  • 整型 (int): 32位有符号整数
  • 无符号整型 (uint): 32位无符号整数
  • 单精度浮点 (float): 32位浮点数
  • 双精度浮点 (double): 64位浮点数
  • 字符串 (string): 字符串数据

支持的PLC地址类型

  • X: 输入继电器
  • Y: 输出继电器
  • M: 内部继电器
  • D: 数据寄存器
  • 其他: 根据三菱PLC型号支持的地址类型

核心组件

1. McConnectInfo

MC 协议连接信息类,包含以下配置:

  • Address: PLC 的 IP 地址
  • Port: 通信端口号,默认 6000
  • TimeOut: 超时时间,单位毫秒
  • ReConnectSeconds: 重连间隔时间,单位秒
  • RequestFrame: McpX 帧类型,可选 E3E4
  • IsAscii: 是否使用 ASCII 帧,默认 false
  • IsUdp: 是否使用 UDP,默认 false
  • Password: 远程口令,可选
  • Version: 兼容旧配置字段,Qna_3E 会映射为 E3A_1E 不再支持
2. McItem<T>

单个数据项操作类,继承自DataItem<T>,支持:

  • 读取单个地址的数据
  • 写入单个地址的数据
  • 支持所有基本数据类型
3. McArray<T>

数组数据操作类,继承自ArrayNode<T>,支持:

  • 批量读取连续地址的数据
  • 批量写入连续地址的数据
  • 自动数据变化检测
  • Reactive流支持
4. McConnector

连接管理器,负责:

  • 管理与PLC的连接
  • 连接池管理
  • 自动重连机制
  • 连接状态监控
5. McInstaller

XML类型注册器,用于配置文件的序列化和反序列化

地址格式

McpX 需要把 PLC 地址拆分为 Prefix + 数值地址,项目内部会自动把配置中的 Addr 字符串解析为 McpX 所需格式。

常用地址示例

  • X0: 输入继电器 X0
  • Y10: 输出继电器 Y10
  • M100: 内部继电器 M100
  • D0: 数据寄存器 D0
  • ZR200: 文件寄存器 ZR200

配置字段

  • McItem<T>.Addr: 单个点位地址,例如 D100
  • McArray<T>.Addr: 数组起始地址,例如 M0

注意事项

  1. 目标框架: 使用 .NET Standard 2.0
  2. 依赖库: 使用 NuGet 包 McpX
  3. 协议支持: 当前支持 McpX 可覆盖的 3E/4E 帧,不支持 A_1E
  4. 地址格式: 地址必须是前缀加数值的标准 MC 地址,例如 D100M0
  5. 数组长度: 数组读取长度由数组中的 DataItem 数量决定,需保证配置项连续
  6. 数据类型: 请确保 PLC 中的实际数据类型与泛型参数一致

配置示例

<Connection xsi:type="McConnectInfo">
	<Id>mc1</Id>
	<Address>192.168.1.100</Address>
	<Port>6000</Port>
	<TimeOut>5000</TimeOut>
	<ReConnectSeconds>1</ReConnectSeconds>
	<RequestFrame>E3</RequestFrame>
	<IsAscii>false</IsAscii>
	<IsUdp>false</IsUdp>
</Connection>

<InputStatus xsi:type="McArrayOfBoolean" Addr="X0" Desc="输入状态">
	<DataItem xsi:type="McItemOfBoolean" Name="启动按钮" Ext="启动按钮状态" />
	<DataItem xsi:type="McItemOfBoolean" Name="停止按钮" Ext="停止按钮状态" />
</InputStatus>

<SystemHeartbeat xsi:type="McItemOfInt16" Addr="D999" Name="系统心跳" Ext="系统心跳" />

错误处理

  • 连接失败时会自动重连
  • 读写操作异常会记录日志
  • 提供详细的错误信息和调试信息

扩展功能

  • 支持Reactive Extensions (Rx)
  • 数据变化自动通知
  • 自动轮询功能
  • 连接状态监控
  • 灵活的配置管理

该项目完全兼容现有的PLC通信架构,可以与Modbus、OPC UA等其他协议项目无缝集成使用。

Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 103 4/23/2026
2.0.0 103 4/23/2026
1.0.0 406 11/26/2025

使用MC协议连接到三菱plc